diff --git a/src/query/service/src/sessions/query_ctx.rs b/src/query/service/src/sessions/query_ctx.rs index 975c9d5e91ec..cbf6b3c63eae 100644 --- a/src/query/service/src/sessions/query_ctx.rs +++ b/src/query/service/src/sessions/query_ctx.rs @@ -154,6 +154,9 @@ pub struct QueryContext { // Used by synchronized generate aggregating indexes when new data written. inserted_segment_locs: Arc>>, target_segment_locs: Arc>, + // Temp table for materialized CTE, first string is the database_name, second string is the table_name + // All temp tables' catalog is `CATALOG_DEFAULT`, so we don't need to store it. + m_cte_temp_table: Arc>>, } impl QueryContext { @@ -180,6 +183,7 @@ impl QueryContext { inserted_segment_locs: Arc::new(RwLock::new(HashSet::new())), block_threshold: Arc::new(RwLock::new(BlockThresholds::default())), target_segment_locs: Arc::new(DashMap::new()), + m_cte_temp_table: Arc::new(Default::default()), }) } diff --git a/src/query/sql/src/planner/binder/ddl/table.rs b/src/query/sql/src/planner/binder/ddl/table.rs index bbfd832b6e32..1ac6461e7b0e 100644 --- a/src/query/sql/src/planner/binder/ddl/table.rs +++ b/src/query/sql/src/planner/binder/ddl/table.rs @@ -1283,7 +1283,6 @@ impl Binder { _hilbert_index \ " ); - let tokens = tokenize_sql(query.as_str())?; let (stmt, _) = parse_sql(&tokens, self.dialect)?; let Statement::Query(query) = &stmt else { @@ -1291,8 +1290,6 @@ impl Binder { }; let mut new_bind_context = BindContext::new(); let (s_expr, new_bind_context) = self.bind_query(&mut new_bind_context, query)?; - // Wrap `LogicalMaterializedCte` to `s_expr` - let s_expr = new_bind_context.cte_context.wrap_m_cte(s_expr); let new_bind_context = Box::new(new_bind_context); bind_context.parent = Some(new_bind_context.clone()); let cluster_by = OptimizeClusterBy {