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 0485c9e commit be562fc
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 21 deletions.
5 changes: 0 additions & 5 deletions src/query/ee/tests/it/aggregating_index/index_refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,6 @@ async fn test_sync_agg_index_after_update() -> Result<()> {
.get_settings()
.set_enable_refresh_aggregating_index_after_write(true)?;

// ctx.get_settings()
// .set_enable_refresh_aggregating_index_after_write(true)?;
// let fixture = TestFixture::new_with_ctx(_guard, ctx).await;
// let ctx = fixture.ctx();

// Create table
fixture
.execute_command("CREATE TABLE t0 (a int, b int, c int) storage_format = 'parquet'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ DB.Table: 'system'.'settings', Table: settings-table_id:1, ver:0, Engine: System
| 'enable_query_profiling' | '0' | '0' | '[0, 1]' | 'SESSION' | 'Enables recording query profile' | 'UInt64' |
| 'enable_query_result_cache' | '0' | '0' | '[0, 1]' | 'SESSION' | 'Enables caching query results to improve performance for identical queries.' | 'UInt64' |
| 'enable_recluster_after_write' | '1' | '1' | 'None' | 'SESSION' | 'Enables re-clustering after write(copy/replace-into).' | 'UInt64' |
| 'enable_refresh_aggregating_index_after_write' | '0' | '0' | '[0, 1]' | 'SESSION' | 'Refresh aggregating index after new data written' | 'UInt64' |
| 'enable_refresh_virtual_column_after_write' | '0' | '0' | '[0, 1]' | 'SESSION' | 'Refresh virtual column after new data written' | 'UInt64' |
| 'enable_refresh_aggregating_index_after_write' | '1' | '1' | '[0, 1]' | 'SESSION' | 'Refresh aggregating index after new data written' | 'UInt64' |
| 'enable_refresh_virtual_column_after_write' | '1' | '1' | '[0, 1]' | 'SESSION' | 'Refresh virtual column after new data written' | 'UInt64' |
| 'enable_replace_into_bloom_pruning' | '1' | '1' | '[0, 1]' | 'SESSION' | 'Enables bloom pruning for replace-into statement.' | 'UInt64' |
| 'enable_replace_into_partitioning' | '1' | '1' | '[0, 1]' | 'SESSION' | 'Enables partitioning for replace-into statement (if table has cluster keys).' | 'UInt64' |
| 'enable_runtime_filter' | '0' | '0' | '[0, 1]' | 'SESSION' | 'Enables runtime filter optimization for JOIN.' | 'UInt64' |
Expand Down
4 changes: 2 additions & 2 deletions src/query/settings/src/settings_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ impl DefaultSettings {
range: None,
}),
("enable_refresh_aggregating_index_after_write", DefaultSettingValue {
value: UserSettingValue::UInt64(0),
value: UserSettingValue::UInt64(1),
desc: "Refresh aggregating index after new data written",
mode: SettingMode::Both,
range: Some(SettingRange::Numeric(0..=1)),
Expand Down Expand Up @@ -612,7 +612,7 @@ impl DefaultSettings {
range: Some(SettingRange::String(vec!["None", "LZ4", "ZSTD"])),
}),
("enable_refresh_virtual_column_after_write", DefaultSettingValue {
value: UserSettingValue::UInt64(0),
value: UserSettingValue::UInt64(1),
desc: "Refresh virtual column after new data written",
mode: SettingMode::Both,
range: Some(SettingRange::Numeric(0..=1)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ CREATE DATABASE test_virtual_column
statement ok
USE test_virtual_column

statement ok
SET enable_refresh_virtual_column_after_write=1;

statement ok
drop table if exists t1

Expand Down Expand Up @@ -222,9 +219,6 @@ SELECT r.id, r.val['a'], r.nval:a FROM ( SELECT r.id, r.val, r.val as nval FROM
5 55 55
6 NULL NULL

statement ok
SET enable_refresh_virtual_column_after_write=0;

statement ok
DROP DATABASE test_virtual_column

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ use test_sync_agg_index
statement ok
DROP AGGREGATING INDEX IF EXISTS testi;

statement ok
SET enable_refresh_aggregating_index_after_write=1;

statement ok
CREATE TABLE t (a int, b int, c int)

Expand All @@ -48,9 +45,6 @@ SELECT b, SUM(a) from t WHERE c > 1 GROUP BY b ORDER BY b
2 3
3 1

statement ok
SET enable_refresh_aggregating_index_after_write=0;

statement ok
DROP AGGREGATING INDEX testi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,54 @@ EvalScalar
├── rewritten query: [selection: [index_col_0 (#0)]]
└── estimated rows: 0.00

# for sync aggregating index

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

statement ok
truncate table t1

# Should not be rewritten
query T
EXPLAIN SELECT b, a + 1 as x from t1 order by x
Expand Down

0 comments on commit be562fc

Please sign in to comment.