Skip to content

Commit

Permalink
add explain for sync agg index
Browse files Browse the repository at this point in the history
  • Loading branch information
ariesdevil committed Dec 18, 2023
1 parent ce9acb4 commit 9d9d0a5
Showing 1 changed file with 56 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,27 +289,76 @@ EvalScalar
├── rewritten query: [selection: [index_col_0 (#0)]]
└── estimated rows: 0.00

# for sync aggregating index

statement ok
SET enable_refresh_aggregating_index_after_write=1;

statement ok
DROP AGGREGATING INDEX idx1

statement ok
CREATE SYNC AGGREGATING INDEX idx1 AS SELECT a + 1 from t1

statement ok
INSERT INTO t1 VALUES (1,1), (1,2), (2,4), (2,5)

query T
EXPLAIN SELECT avg(a + 1) from t1
----
EvalScalar
├── output columns: [(sum((a + 1)) / if((count((a + 1)) = 0), 1, count((a + 1)))) (#5)]
├── expressions: [sum((a + 1)) (#3) / CAST(if(CAST(count((a + 1)) (#4) = 0 AS Boolean NULL), 1, count((a + 1)) (#4)) AS UInt64 NULL)]
├── estimated rows: 1.00
└── AggregateFinal
├── output columns: [sum((a + 1)) (#3), count((a + 1)) (#4)]
├── group by: []
├── aggregate functions: [sum(sum_arg_0), count()]
├── estimated rows: 1.00
└── AggregatePartial
├── output columns: [sum((a + 1)) (#3), count((a + 1)) (#4)]
├── group by: []
├── aggregate functions: [sum(sum_arg_0), count()]
├── estimated rows: 1.00
└── EvalScalar
├── output columns: [sum_arg_0 (#2)]
├── expressions: [t1.a (#0) + 1]
├── estimated rows: 4.00
└── TableScan
├── table: default.test_index_db.t1
├── output columns: [a (#0)]
├── read rows: 4
├── read bytes: 47
├── partitions total: 1
├── partitions scanned: 1
├── pruning stats: [segments: <range pruning: 1 to 1>, blocks: <range pruning: 1 to 1, bloom pruning: 0 to 0>]
├── push downs: [filters: [], limit: NONE]
├── aggregating index: [SELECT (a + 1) FROM test_index_db.t1]
├── rewritten query: [selection: [index_col_0 (#0)]]
└── estimated rows: 4.00

# Should not be rewritten
query T
EXPLAIN SELECT b, a + 1 as x from t1 order by x
----
Sort
├── output columns: [t1.b (#1), x (#2)]
├── sort keys: [x ASC NULLS LAST]
├── estimated rows: 0.00
├── estimated rows: 4.00
└── EvalScalar
├── output columns: [t1.b (#1), x (#2)]
├── expressions: [t1.a (#0) + 1]
├── estimated rows: 0.00
├── estimated rows: 4.00
└── TableScan
├── table: default.test_index_db.t1
├── output columns: [a (#0), b (#1)]
├── read rows: 0
├── read bytes: 0
├── partitions total: 0
├── partitions scanned: 0
├── read rows: 4
├── read bytes: 94
├── partitions total: 1
├── partitions scanned: 1
├── pruning stats: [segments: <range pruning: 1 to 1>, blocks: <range pruning: 1 to 1, bloom pruning: 0 to 0>]
├── push downs: [filters: [], limit: NONE]
└── estimated rows: 0.00
└── estimated rows: 4.00

statement ok
DROP AGGREGATING INDEX idx1
Expand Down

0 comments on commit 9d9d0a5

Please sign in to comment.