diff --git a/src/query/src/dummy_catalog.rs b/src/query/src/dummy_catalog.rs index 17a5995ea1bc..c4ae1de03afa 100644 --- a/src/query/src/dummy_catalog.rs +++ b/src/query/src/dummy_catalog.rs @@ -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}; @@ -177,7 +179,27 @@ impl TableProvider for DummyTableProvider { &self, filters: &[&Expr], ) -> datafusion::error::Result> { - 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) } } diff --git a/tests/cases/standalone/common/select/prune.result b/tests/cases/standalone/common/select/prune.result index c6884bddccd5..f2718926c97a 100644 --- a/tests/cases/standalone/common/select/prune.result +++ b/tests/cases/standalone/common/select/prune.result @@ -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 diff --git a/tests/cases/standalone/common/select/prune.sql b/tests/cases/standalone/common/select/prune.sql index fb007105ed58..e7fd643537a1 100644 --- a/tests/cases/standalone/common/select/prune.sql +++ b/tests/cases/standalone/common/select/prune.sql @@ -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;