-
Notifications
You must be signed in to change notification settings - Fork 4.1k
optimizer not take into account expression index (even with index hinting) #83390
Copy link
Copy link
Closed
Closed
Copy link
Labels
C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.O-communityOriginated from the communityOriginated from the communityT-sql-queriesSQL Queries TeamSQL Queries TeamX-blathers-triagedblathers was able to find an ownerblathers was able to find an owner
Description
cockroachdb version 22.1
create table why_u_no_use_index (id uuid, long_text text);
insert into why_u_no_use_index (select gen_random_uuid(), random() * 100 from generate_series(1, 100000));
create index null_check on why_u_no_use_index((long_text is null));
explain analyze select * from why_u_no_use_index where long_text is null limit 100;# postgres
postgres=# explain analyze select * from why_u_no_use_index where long_text is null limit 100;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.29..4.31 rows=1 width=32) (actual time=0.075..0.075 rows=0 loops=1)
-> Index Scan using null_check on why_u_no_use_index (cost=0.29..4.31 rows=1 width=32) (actual time=0.074..0.074 rows=0 loops=1)
Index Cond: ((long_text IS NULL) = true)
Filter: (long_text IS NULL)
Planning Time: 0.168 ms
Execution Time: 0.093 ms
(6 rows)# cockroachdb
root@:26257/defaultdb> explain analyze select * from why_u_no_use_index@null_check where long_text is null limit 100;
info
---------------------------------------------------------------
planning time: 579µs
execution time: 12.5s
distribution: full
vectorized: true
rows read from KV: 200,000 (9.0 MiB)
cumulative time spent in KV: 12.5s
maximum memory usage: 10 MiB
network usage: 0 B (0 messages)
• limit
│ nodes: n1
│ actual row count: 0
│ count: 100
│
└── • filter
│ nodes: n1
│ actual row count: 0
│ filter: long_text IS NULL
│
└── • index join
│ nodes: n1
│ actual row count: 100,000
│ KV time: 12.1s
│ KV contention time: 0µs
│ KV rows read: 100,000
│ KV bytes read: 5.3 MiB
│ estimated max memory allocated: 6.4 MiB
│ estimated max sql temp disk usage: 0 B
│ table: why_u_no_use_index@why_u_no_use_index_pkey
│
└── • scan
nodes: n1
actual row count: 100,000
KV time: 477ms
KV contention time: 0µs
KV rows read: 100,000
KV bytes read: 3.6 MiB
estimated max memory allocated: 3.7 MiB
missing stats
table: why_u_no_use_index@null_check
spans: FULL SCAN
(41 rows)
Time: 12.541s total (execution 12.540s / network 0.001s)Jira issue: CRDB-17042
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.O-communityOriginated from the communityOriginated from the communityT-sql-queriesSQL Queries TeamSQL Queries TeamX-blathers-triagedblathers was able to find an ownerblathers was able to find an owner
Type
Projects
Status
Done