Skip to content

[Bug]: VARCHAR equality predicate returns zero rows with owner-bound PK and covering secondary index #25341

Closed

Description

@XuPeng-SH

Is there an existing issue for the same bug?

I have checked the existing issues.

Branch Name

v4.0.0-rc4

Commit ID

Unknown from SQL variables. Reproduced with Docker image matrixorigin/matrixone:4.0.0-rc4.

Other Environment Information

  • Hardware parameters: local Docker Compose development environment
  • OS type: Linux
  • MatrixOne version: 8.0.30-MatrixOne-v4.0.0-rc4
  • Docker image: matrixorigin/matrixone:4.0.0-rc4

Actual Behavior

For a table with an owner-bound composite primary key and a secondary index that includes the VARCHAR predicate column plus the primary-key columns, status = 'active' evaluates to 1 in a row projection, but the same predicate in WHERE returns zero rows.

status <=> 'active' returns the expected row count.

Observed output:

id  status  row_eq  row_nullsafe
a1  active  1       1

count_eq
0

count_nullsafe
1

Expected Behavior

WHERE status = 'active' should return the inserted row, so count_eq should be 1, matching the row-level expression result.

Steps to Reproduce

Run this SQL on MatrixOne 8.0.30-MatrixOne-v4.0.0-rc4:

DROP DATABASE IF EXISTS astra_repro_varchar_predicate;
CREATE DATABASE astra_repro_varchar_predicate;
USE astra_repro_varchar_predicate;

CREATE TABLE t (
    id VARCHAR(64) NOT NULL,
    user_id VARCHAR(64) NOT NULL,
    session_id VARCHAR(64) NOT NULL,
    status VARCHAR(32) NOT NULL,
    due DATETIME(6) NULL,
    PRIMARY KEY (user_id, session_id, id),
    INDEX idx_ret(status, due, user_id, session_id, id)
);

INSERT INTO t
VALUES ('a1', 'u1', 's1', 'active', DATE_ADD(NOW(6), INTERVAL 1 DAY));

SELECT id, status, status = 'active' AS row_eq, status <=> 'active' AS row_nullsafe
FROM t;

SELECT COUNT(*) AS count_eq
FROM t
WHERE status = 'active';

SELECT COUNT(*) AS count_nullsafe
FROM t
WHERE status <=> 'active';

Additional information

This was found while debugging retention queries on a table with this index shape:

PRIMARY KEY (user_id, session_id, artifact_id),
INDEX idx_artifacts_retention (status, retention_until, retention_policy, user_id, session_id, artifact_id)

The broader query WHERE status IN ('active', 'expiring') showed the same symptom: row-level expressions evaluated correctly, while WHERE aggregates returned 0.

Activity

  1. added
    kind/bug
    on Jul 1, 2026
  2. added theissue type on Jul 1, 2026
  3. added this to the MO-202607 milestone on Jul 1, 2026
  4. Ariznawlll commented on Jul 2, 2026

    @Ariznawlll
    Collaborator

    Supplemental composite-PK + composite-secondary-index coverage on latest main 51656deb6:

    The composite primary key itself matched MySQL in a clean control matrix, but once the owner-bound composite-PK table has covering secondary indexes, row-returning predicates on the secondary-index leading VARCHAR columns still miss rows.

    Minimal shape:

    create table indexed_tasks (
      user_id varchar(16) not null,
      session_id varchar(16) not null,
      task_id varchar(16) not null,
      status varchar(12) not null,
      policy varchar(12) null,
      due datetime null,
      score int null,
      amount decimal(10,2) null,
      payload varchar(30),
      primary key(user_id, session_id, task_id),
      key idx_status_due_owner(status, due, user_id, session_id, task_id),
      key idx_policy_owner(policy, user_id, session_id, task_id)
    );

    With rows containing four status='active' records and four policy='keep' records:

    -- MySQL and MO no-secondary-index control
    where status='active' -> 4 rows
    where policy='keep'   -> 4 rows
    
    -- MO indexed table on main 51656deb6
    where status='active' -> 0 rows
    where policy='keep'   -> 0 rows
    

    policy IS NULL did return the expected row, so this repro specifically reinforces the equality/prefix path for non-NULL VARCHAR values on composite secondary indexes with composite-PK columns appended.

  5. added a commit that references this issue on Jul 2, 2026
    2bf7621
  6. assigned and unassigned on Jul 2, 2026
  7. 1 remaining item

  8. Repository owner unassigned on Jul 6, 2026
  9. assigned and unassigned on Jul 7, 2026
  10. ghost closed this as completedon Jul 7, 2026
  11. added 3 commits that reference this issue on Sep 17, 2026
    748d8fb
    b82d168
    fddf0aa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugseverity/s-1

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions