ccoffline opened a new issue #4581:
URL: https://github.com/apache/incubator-doris/issues/4581
**Describe the bug**
When using select condition like "-1=-1" may cause SelectNode.cardinality
computing error.
`// at org.apache.doris.planner.SelectNode.computeStats(SelectNode.java:70)`
`cardinality = Math.round(((double) getChild(0).cardinality) *
computeSelectivity());`
`Preconditions.checkState(cardinality >= 0);`
This cardinality may be less than 0.
**To Reproduce**
Steps to reproduce the behavior:
1. Create a table
> CREATE TABLE \`table1\` (
\`city_id\` bigint(20) NULL,
\`tag_id\` bigint(20) NULL,
\`dt\` bigint(20) NULL,
\`num\` bigint(20) NULL
) ENGINE=OLAP
DUPLICATE KEY(\`city_id\`, \`tag_id\`, \`dt\`)
COMMENT "OLAP"
PARTITION BY RANGE(\`dt\`)
(PARTITION p20200102 VALUES [("20200101"), ("20200102")),
PARTITION p20200103 VALUES [("20200102"), ("20200103")))
DISTRIBUTED BY HASH(\`city_id\`) BUCKETS 5
PROPERTIES (
"replication_num" = "1",
"in_memory" = "false",
"storage_format" = "DEFAULT"
);
You may need to insert some data and wait for the "cardinality" to be > 0 (I
still dont know how the "cardinality" works).
> INSERT INTO table1 VALUES (1, 2, 20200102, 3);
2. Launch a query
> SELECT rank, tag_id
FROM (
SELECT row_number() OVER (ORDER BY num DESC) AS rank, tag_id
FROM table1
) t
WHERE -1=-1 or tag_id in (-1)
LIMIT 10
;
When the table is not empty (maybe), the cardinality will be > 0,
`computeSelectivity()` < 0, then the error occur.
I tried to reduce some elements and this is the minimum sql to reproduce the
bug.
Could someone explain what does the cardinality and selectivity means? Is
`Preconditions.checkState(cardinality >= 0);` neccessary?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]