Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable optimizer to generate index merge path for mv index + OR list nested in AND list #51778

Closed
time-and-fate opened this issue Mar 14, 2024 · 0 comments · Fixed by #51716
Closed
Assignees
Labels
sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.

Comments

@time-and-fate
Copy link
Member

Enhancement

Currently, tidb can't generate index merge access path for such case:

CREATE TABLE `t` (
  `a` int(11) DEFAULT NULL,
  `b` varchar(30) DEFAULT NULL,
  `c` float DEFAULT NULL,
  `j` json DEFAULT NULL,
  `pk` int(11) NOT NULL,
  PRIMARY KEY (`pk`) /*T![clustered_index] CLUSTERED */,
  KEY `mvi1` (`c`,(cast(json_extract(`j`, _utf8'$.a') as unsigned array)),`b`),
  KEY `mvi2` (`a`,(cast(json_extract(`j`, _utf8'$.c') as unsigned array))),
  KEY `mvi3` ((cast(json_extract(`j`, _utf8'$.d') as unsigned array)),`c`),
  KEY `idx` (`b`,`c`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

explain format=brief select /*+ use_index_merge(t, mvi1) */ * from t where ( 1 member of (j->'$.a') or  2 member of (j->'$.a') ) and a = 20 and c = 10;
> explain format=brief select /*+ use_index_merge(t, mvi1) */ * from t where ( 1 member of (j->'$.a') or  2 member of (j->'$.a') ) and a = 20 and c = 10;
+-----------------------+----------+-----------+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id                    | estRows  | task      | access object | operator info                                                                                                                                                                  |
+-----------------------+----------+-----------+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| TableReader           | 0.01     | root      |               | data:Selection                                                                                                                                                                 |
| └─Selection           | 0.01     | cop[tikv] |               | eq(test.t.a, 20), eq(test.t.c, 10), or(json_memberof(cast(1, json BINARY), json_extract(test.t.j, "$.a")), json_memberof(cast(2, json BINARY), json_extract(test.t.j, "$.a"))) |
|   └─TableFullScan     | 10000.00 | cop[tikv] | table:t       | keep order:false, stats:pseudo                                                                                                                                                 |
+-----------------------+----------+-----------+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3 rows in set, 1 warning (0.004 sec)
@time-and-fate time-and-fate added type/enhancement The issue or PR belongs to an enhancement. sig/planner SIG: Planner labels Mar 14, 2024
@time-and-fate time-and-fate self-assigned this Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant