Skip to content

Fix the query plan of count(*) META_SCAN #65886

@murphyatwork

Description

@murphyatwork

Steps to reproduce the behavior (Required)

Normal META_SCAN return a correct count:

MySQL [email protected]:d1> explain costs SELECT
                  ->        cast(COUNT(k1) AS BIGINT)
                  -> FROM
                  ->        `test_array_collection_size1` partitions (`test_array_collection_size1`) [_META_];


|   0:MetaScan                                                                                                              |
|      Table: test_array_collection_size1                                                                                   |
|      <id 6> : count_k1                                                                                                    |
|      Partitions: [test_array_collection_size1]                                                                            |
|      cardinality: 1                                                                                                       |
|      column statistics:                                                                                                   |
|      * count_k1-->[1.0, 1.0, 0.0, 4.0, 1.0] ESTIMATE                                                                      |

count(*) return 0:

MySQL [email protected]:d1> explain costs SELECT
                  ->        cast(COUNT(*) AS BIGINT)
                  -> FROM
                  ->        `test_array_collection_size1` partitions (`test_array_collection_size1`) [_META_];

   1:Project                                                                                      |
|   |  output columns:                                                                             |
|   |  7 <-> 1                                                                                     |
|   |  cardinality: 1                                                                              |
|   |  column statistics:                                                                          |
|   |  * auto_fill_col-->[1.0, 1.0, 0.0, 1.0, 1.0] ESTIMATE                                        |
|   |                                                                                              |
|   0:MetaScan                                                                                     |
|      Table: test_array_collection_size1                                                          |
|      Partitions: [test_array_collection_size1]                                                   |
|      cardinality: 1                                                                              |
|      column statistics:                                                                          |
|      * k1-->[1.0, 1.0, 0.0, 4.0, 1.0] ESTIMATE                                                   |
|      * p_date-->[1.6725024E9, 1.6725024E9, 0.0, 4.0, 1.0] ESTIMATE                               |
|      * int_arr-->[-Infinity, Infinity, 0.0, 12.0, 1.0] COS: 3.0 ESTIMATE                         |
|      * str_arr-->[-Infinity, Infinity, 0.0, 48.0, 1.0] COS: 3.0 ESTIMATE                         |
+--------------------------------------------------------------------------------------------------+

To conclude, count(*) [_META_SCAN] cannot choose a correct column, leading to incorrect query result.

Expected behavior (Required)

Correct count.

Real behavior (Required)

the count is 0.

StarRocks version (Required)

  • You can get the StarRocks version by executing SQL select current_version()
  • branch main 20251124

Metadata

Metadata

Assignees

Labels

type/bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions