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

optimizer does not consider using ordered index scan when is null is used #54188

Closed
mzhang77 opened this issue Jun 24, 2024 · 2 comments · Fixed by #54253
Closed

optimizer does not consider using ordered index scan when is null is used #54188

mzhang77 opened this issue Jun 24, 2024 · 2 comments · Fixed by #54253
Labels
report/customer Customers have encountered this bug. sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.

Comments

@mzhang77
Copy link

mzhang77 commented Jun 24, 2024

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE `testnull` (
       `object_id` bigint(20) unsigned NOT NULL,
       `a` bigint(20) DEFAULT NULL,
       `b` bigint(20) DEFAULT NULL,
       PRIMARY KEY (`object_id`) /*T![clustered_index] CLUSTERED */,
       KEY `ab` (`a`,`b`)
);

explain select * from testnull where a is null order by b;

2. What did you expect to see? (Required)

execution plan use index ab and keep order on b to avoid sorting

3. What did you see instead (Required)

mysql> explain select * from testnull where a is null order by b;
+--------------------------+---------+-----------+--------------------------------+---------------------------------------------------+
| id                       | estRows | task      | access object                  | operator info                                     |
+--------------------------+---------+-----------+--------------------------------+---------------------------------------------------+
| Sort_5                   | 10.00   | root      |                                | test.testnull.b                                   |
| └─IndexReader_9          | 10.00   | root      |                                | index:IndexRangeScan_8                            |
|   └─IndexRangeScan_8     | 10.00   | cop[tikv] | table:testnull, index:ab(a, b) | range:[NULL,NULL], keep order:false, stats:pseudo |
+--------------------------+---------+-----------+--------------------------------+---------------------------------------------------+
3 rows in set (0.01 sec)

mysql> explain select /*+ order_index(testnull, ab) */ * from testnull where a is null order by b;
ERROR 1815 (HY000): Internal : Can't find a proper physical plan for this query

4. What is your TiDB version? (Required)

mysql> select @@version\g;
+--------------------+
| @@version          |
+--------------------+
| 8.0.11-TiDB-v8.1.0 |
+--------------------+
1 row in set (0.00 sec)
@mzhang77 mzhang77 added the type/bug The issue is confirmed as a bug. label Jun 24, 2024
@hawkingrei hawkingrei added the sig/planner SIG: Planner label Jun 25, 2024
@winoros winoros added type/enhancement The issue or PR belongs to an enhancement. and removed type/bug The issue is confirmed as a bug. labels Jun 25, 2024
@winoros winoros changed the title optimizer does not consider index when is null is used optimizer does not consider using ordered index scan when is null is used Jun 25, 2024
@winoros
Copy link
Member

winoros commented Jun 25, 2024

ISNULL is not treated as point range currently.

@seiya-annie
Copy link

/found customer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
report/customer Customers have encountered this bug. sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
6 participants