This is an automated email from the ASF dual-hosted git repository.

jiacai2050 pushed a commit to branch memtable-poc
in repository https://gitbox.apache.org/repos/asf/incubator-horaedb.git


The following commit(s) were added to refs/heads/memtable-poc by this push:
     new 56feebab feat: block support query range
56feebab is described below

commit 56feebabfa024b1cf308f3c45569a1dd4effbf11
Author: jiacai2050 <[email protected]>
AuthorDate: Wed Jan 3 15:15:29 2024 +0800

    feat: block support query range
---
 proxy/src/limiter.rs       | 14 ++++++++++++++
 query_frontend/src/plan.rs | 12 ++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/proxy/src/limiter.rs b/proxy/src/limiter.rs
index 9405dd9e..d2422b72 100644
--- a/proxy/src/limiter.rs
+++ b/proxy/src/limiter.rs
@@ -33,8 +33,11 @@ pub enum Error {
 define_result!(Error);
 
 #[derive(Clone, Copy, Deserialize, Debug, PartialEq, Eq, Hash, Serialize, 
PartialOrd, Ord)]
+#[serde(tag = "type", content = "content")]
 pub enum BlockRule {
     QueryWithoutPredicate,
+    /// Max time range a query can scan.
+    QueryRange(i64),
     AnyQuery,
     AnyInsert,
 }
@@ -52,6 +55,17 @@ impl BlockRule {
         match self {
             BlockRule::QueryWithoutPredicate => 
self.is_query_without_predicate(plan),
             BlockRule::AnyQuery => matches!(plan, Plan::Query(_)),
+            BlockRule::QueryRange(threshold) => {
+                if let Plan::Query(plan) = plan {
+                    if let Some(range) = plan.query_range() {
+                        if range > *threshold {
+                            return true;
+                        }
+                    }
+                }
+
+                false
+            }
             BlockRule::AnyInsert => matches!(plan, Plan::Insert(_)),
         }
     }
diff --git a/query_frontend/src/plan.rs b/query_frontend/src/plan.rs
index 05742231..581fae52 100644
--- a/query_frontend/src/plan.rs
+++ b/query_frontend/src/plan.rs
@@ -196,6 +196,18 @@ impl QueryPlan {
 
         Some(priority)
     }
+
+    /// When query contains invalid time range such as `[200, 100]`, it will
+    /// return None.
+    pub fn query_range(&self) -> Option<i64> {
+        self.extract_time_range().map(|time_range| {
+            time_range
+                .exclusive_end()
+                .as_i64()
+                .checked_sub(time_range.inclusive_start().as_i64())
+                .unwrap_or(i64::MAX)
+        })
+    }
 }
 
 impl Debug for QueryPlan {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to