Skip to content

Commit

Permalink
perf: set simple filter on primary key columns to exact filter (Grept…
Browse files Browse the repository at this point in the history
…imeTeam#4564)

* perf: set simple filter on primary key columns to exact filter

Signed-off-by: Ruihang Xia <[email protected]>

* add sqlness test

Signed-off-by: Ruihang Xia <[email protected]>

* fix typo

Signed-off-by: Ruihang Xia <[email protected]>

* fix sqlness

Signed-off-by: Ruihang Xia <[email protected]>

---------

Signed-off-by: Ruihang Xia <[email protected]>
  • Loading branch information
waynexia authored Aug 19, 2024
1 parent 975b8c6 commit 8de11a0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/query/src/dummy_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
use std::any::Any;
use std::sync::{Arc, Mutex};

use api::v1::SemanticType;
use async_trait::async_trait;
use common_recordbatch::filter::SimpleFilterEvaluator;
use common_recordbatch::OrderOption;
use datafusion::catalog::schema::SchemaProvider;
use datafusion::catalog::{CatalogProvider, CatalogProviderList};
Expand Down Expand Up @@ -177,7 +179,27 @@ impl TableProvider for DummyTableProvider {
&self,
filters: &[&Expr],
) -> datafusion::error::Result<Vec<TableProviderFilterPushDown>> {
Ok(vec![TableProviderFilterPushDown::Inexact; filters.len()])
let supported = filters
.iter()
.map(|e| {
// Simple filter on primary key columns are precisely evaluated.
if let Some(simple_filter) = SimpleFilterEvaluator::try_new(e) {
if self
.metadata
.column_by_name(simple_filter.column_name())
.and_then(|c| (c.semantic_type == SemanticType::Tag).then_some(()))
.is_some()
{
TableProviderFilterPushDown::Exact
} else {
TableProviderFilterPushDown::Inexact
}
} else {
TableProviderFilterPushDown::Inexact
}
})
.collect();
Ok(supported)
}
}

Expand Down
17 changes: 17 additions & 0 deletions tests/cases/standalone/common/select/prune.result
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ select * from demo where collector='disk' order by ts;
| 1970-01-01T00:00:00.002 | 3.0 | test2 | idc1 | disk |
+-------------------------+-------+-------+------+-----------+

-- SQLNESS REPLACE (-+) -
-- SQLNESS REPLACE (\s\s+) _
-- SQLNESS REPLACE (peers.*) REDACTED
-- SQLNESS REPLACE (metrics.*) REDACTED
-- SQLNESS REPLACE region=\d+\(\d+,\s+\d+\) region=REDACTED
explain analyze select * from demo where idc='idc1';

+-+-+-+
| stage | node | plan_|
+-+-+-+
| 0_| 0_|_MergeScanExec: REDACTED
|_|_|_|
| 1_| 0_|_SeqScan: region=REDACTED, partition_count=1 (1 memtable ranges, 0 file ranges) REDACTED
|_|_|_|
|_|_| Total rows: 2_|
+-+-+-+

drop table demo;

Affected Rows: 0
Expand Down
7 changes: 7 additions & 0 deletions tests/cases/standalone/common/select/prune.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ select * from demo where idc='idc1' order by ts;

select * from demo where collector='disk' order by ts;

-- SQLNESS REPLACE (-+) -
-- SQLNESS REPLACE (\s\s+) _
-- SQLNESS REPLACE (peers.*) REDACTED
-- SQLNESS REPLACE (metrics.*) REDACTED
-- SQLNESS REPLACE region=\d+\(\d+,\s+\d+\) region=REDACTED
explain analyze select * from demo where idc='idc1';

drop table demo;

0 comments on commit 8de11a0

Please sign in to comment.