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

Stats of multi-column mv index isn't fully utilized for estimation #56915

Closed
time-and-fate opened this issue Oct 28, 2024 · 0 comments · Fixed by #56850
Closed

Stats of multi-column mv index isn't fully utilized for estimation #56915

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

Comments

@time-and-fate
Copy link
Member

Enhancement

create table t(a int, b int, j json, index ia(a), index mvi( (cast(j as signed array)), a, b) );
insert into t value(1,1,'[1,2,3,4,5]');
insert into t value(1,1,'[1,2,3,4,5]');
insert into t value(1,1,'[1,2,3,4,5]');
insert into t value(1,1,'[1,2,3,4,5]');
insert into t value(1,1,'[6]');
analyze table t all columns;
explain select * from t where a = 1 and 6 member of (j);

The actual row count is 1.

Expected

> explain select * from t where a = 1 and 6 member of (j);
+--------------------------------+---------+-----------+-----------------------------------------------------+-------------------------------------------------------------------+
| id                             | estRows | task      | access object                                       | operator info                                                     |
+--------------------------------+---------+-----------+-----------------------------------------------------+-------------------------------------------------------------------+
| IndexMerge_14                  | 1.00    | root      |                                                     | type: union                                                       |
| ├─IndexRangeScan_12(Build)     | 1.00    | cop[tikv] | table:t, index:mvi(cast(`j` as signed array), a, b) | range:[6 1,6 1], keep order:false, stats:partial[j:unInitialized] |
| └─TableRowIDScan_13(Probe)     | 1.00    | cop[tikv] | table:t                                             | keep order:false, stats:partial[j:unInitialized]                  |
+--------------------------------+---------+-----------+-----------------------------------------------------+-------------------------------------------------------------------+

Actual

> explain select * from t where a = 1 and 6 member of (j);
+-------------------------+---------+-----------+---------------+----------------------------------------------------------------+
| id                      | estRows | task      | access object | operator info                                                  |
+-------------------------+---------+-----------+---------------+----------------------------------------------------------------+
| TableReader_7           | 5.00    | root      |               | data:Selection_6                                               |
| └─Selection_6           | 5.00    | cop[tikv] |               | eq(test.t.a, 1), json_memberof(cast(6, json BINARY), test.t.j) |
|   └─TableFullScan_5     | 5.00    | cop[tikv] | table:t       | keep order:false, stats:partial[j:unInitialized]               |
+-------------------------+---------+-----------+---------------+----------------------------------------------------------------+
3 rows in set (0.031 sec)

> explain select * from t use index (mvi) where a = 1 and 6 member of (j);
+-------------------------------+---------+-----------+-----------------------------------------------------+-------------------------------------------------------------------+
| id                            | estRows | task      | access object                                       | operator info                                                     |
+-------------------------------+---------+-----------+-----------------------------------------------------+-------------------------------------------------------------------+
| IndexMerge_7                  | 5.00    | root      |                                                     | type: union                                                       |
| ├─IndexRangeScan_5(Build)     | 21.00   | cop[tikv] | table:t, index:mvi(cast(`j` as signed array), a, b) | range:[6 1,6 1], keep order:false, stats:partial[j:unInitialized] |
| └─TableRowIDScan_6(Probe)     | 5.00    | cop[tikv] | table:t                                             | keep order:false, stats:partial[j:unInitialized]                  |
+-------------------------------+---------+-----------+-----------------------------------------------------+-------------------------------------------------------------------+

Please see the PR for the specific reason.

@time-and-fate time-and-fate added type/enhancement The issue or PR belongs to an enhancement. sig/planner SIG: Planner labels Oct 28, 2024
@time-and-fate time-and-fate self-assigned this Oct 28, 2024
ti-chi-bot bot pushed a commit that referenced this issue Oct 28, 2024
…backoff" entry stats can't use iteself for estimation (#56850)

close #56915
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
1 participant