Fix index analysis with indexHint as well

This commit is contained in:
Amos Bird 2023-07-19 10:54:26 +08:00
parent d7bb006c23
commit ec22337284
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
3 changed files with 18 additions and 1 deletions

View File

@ -976,7 +976,15 @@ void ActionsMatcher::visit(const ASTFunction & node, const ASTPtr & ast, Data &
if (node.name == "indexHint")
{
if (data.only_consts)
{
/// We need to collect constants inside `indexHint` for index analysis.
if (node.arguments)
{
for (const auto & arg : node.arguments->children)
visit(arg, data);
}
return;
}
/// Here we create a separate DAG for indexHint condition.
/// It will be used only for index analysis.

View File

@ -1,16 +1,24 @@
DROP TABLE IF EXISTS t0;
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS t2;
CREATE TABLE t0 (c0 Int16, projection h (SELECT min(c0), max(c0), count() GROUP BY -c0)) ENGINE = MergeTree ORDER BY ();
INSERT INTO t0(c0) VALUES (1);
SELECT count() FROM t0 GROUP BY gcd(-sign(c0), -c0);
SELECT count() FROM t0 GROUP BY gcd(-sign(c0), -c0) SETTINGS optimize_use_implicit_projections = 1;
create table t1 (c0 Int32) engine = MergeTree order by sin(c0);
insert into t1 values (-1), (1);
select c0 from t1 order by sin(-c0) settings optimize_read_in_order=0;
select c0 from t1 order by sin(-c0) settings optimize_read_in_order=1;
CREATE TABLE t2 (p Nullable(Int64), k Decimal(76, 39)) ENGINE = MergeTree PARTITION BY toDate(p) ORDER BY k SETTINGS index_granularity = 1, allow_nullable_key = 1;
INSERT INTO t2 FORMAT Values ('2020-09-01 00:01:02', 1), ('2020-09-01 20:01:03', 2), ('2020-09-02 00:01:03', 3);
SELECT count() FROM t2 WHERE indexHint(p = 1.) SETTINGS optimize_use_implicit_projections = 1;
DROP TABLE t0;
DROP TABLE t1;
DROP TABLE t2;