StarRocks / starrocks

StarRocks, a Linux Foundation project, is a next-generation sub-second MPP OLAP database for full analytics scenarios, including multi-dimensional analytics, real-time analytics, and ad-hoc queries.
https://starrocks.io
Apache License 2.0
8.62k stars 1.74k forks source link

[column_with_row] can't take Short Circuit Scan, when pk_column(boolean) = 1/0 #38938

Closed tiannan-sr closed 1 month ago

tiannan-sr commented 7 months ago

Steps to reproduce the behavior (Required)

mysql> set enable_short_circuit = true;
Query OK, 0 rows affected (0.00 sec)

mysql> create table pk(a boolean, b int) primary key(a) distributed by hash(a) properties("storage_type"="column_with_row");
Query OK, 0 rows affected (0.18 sec)

mysql> insert into pk values(1, 1),(0, 2),(1, 3);
Query OK, 3 rows affected (0.43 sec)
{'label':'insert_80449f1c-b07f-11ee-a48e-00163e1b7912', 'status':'VISIBLE', 'txnId':'6560'}

mysql> explain select * from pk where a = 1;
+-----------------------------------------------------+
| Explain String                                      |
+-----------------------------------------------------+
| PLAN FRAGMENT 0                                     |
|  OUTPUT EXPRS:1: a | 2: b                           |
|   PARTITION: UNPARTITIONED                          |
|                                                     |
|   RESULT SINK                                       |
|                                                     |
|   1:EXCHANGE                                        |
|                                                     |
| PLAN FRAGMENT 1                                     |
|  OUTPUT EXPRS:                                      |
|   PARTITION: RANDOM                                 |
|                                                     |
|   STREAM DATA SINK                                  |
|     EXCHANGE ID: 01                                 |
|     UNPARTITIONED                                   |
|                                                     |
|   0:OlapScanNode                                    |
|      TABLE: pk                                      |
|      PREAGGREGATION: ON                             |
|      PREDICATES: CAST(1: a AS TINYINT) = 1          |
|      partitions=1/1                                 |
|      rollup: pk                                     |
|      tabletRatio=6/6                                |
|      tabletList=60818,60822,60826,60830,60834,60838 |
|      cardinality=1                                  |
|      avgRowSize=5.0                                 |
+-----------------------------------------------------+
26 rows in set (0.00 sec)

mysql> explain select * from pk where a = true;
+-----------------------------------------------------+
| Explain String                                      |
+-----------------------------------------------------+
| PLAN FRAGMENT 0                                     |
|  OUTPUT EXPRS:1: a | 2: b                           |
|   PARTITION: RANDOM                                 |
|                                                     |
|   RESULT SINK                                       |
|                                                     |
|   0:OlapScanNode                                    |
|      TABLE: pk                                      |
|      PREAGGREGATION: OFF. Reason: null              |
|      PREDICATES: 1: a                               |
|      partitions=1/1                                 |
|      rollup: pk                                     |
|      tabletRatio=6/6                                |
|      tabletList=60818,60822,60826,60830,60834,60838 |
|      cardinality=-1                                 |
|      avgRowSize=0.0                                 |
|      Short Circuit Scan: true                       |
+-----------------------------------------------------+
17 rows in set (0.00 sec)

Expected behavior (Required)

Short Circuit Scan: true, when k5(boolean) = 1/0

Real behavior (Required)

can't take Short Circuit Scan, when k5(boolean) = 1/0

StarRocks version (Required)

github-actions[bot] commented 1 month ago

We have marked this issue as stale because it has been inactive for 6 months. If this issue is still relevant, removing the stale label or adding a comment will keep it active. Otherwise, we'll close it in 10 days to keep the issue queue tidy. Thank you for your contribution to StarRocks!