diff --git a/deps/oblib/src/lib/ob_define.h b/deps/oblib/src/lib/ob_define.h index 24ad68f4bb..977f4a2d01 100644 --- a/deps/oblib/src/lib/ob_define.h +++ b/deps/oblib/src/lib/ob_define.h @@ -903,7 +903,6 @@ const uint64_t OB_MAX_LS_INNER_TABLE_ID = 49500; // (49500, 49999) for cte, cte table opens up a separate id space, which does not conflict with other id const uint64_t OB_MIN_CTE_TABLE_ID = 49500; const uint64_t OB_MAX_CTE_TABLE_ID = 49999; -const uint64_t OB_MIN_CTE_COLUMN_ID = 0; // (50000, 60000) for inner lob meta table // (60000, 70000) for inner lob piece table const uint64_t OB_MIN_SYS_LOB_META_TABLE_ID = 50000; diff --git a/src/share/schema/ob_column_schema.h b/src/share/schema/ob_column_schema.h index e6d217f344..0792bffa97 100644 --- a/src/share/schema/ob_column_schema.h +++ b/src/share/schema/ob_column_schema.h @@ -200,7 +200,7 @@ public: inline uint64_t get_sequence_id() const { return sequence_id_; } inline int64_t get_encoding_type() const { return encoding_type_; } - inline int64_t get_cte_generate_column_projector_offset() const { return get_column_id();} + inline int64_t get_cte_generate_column_projector_offset() const { return get_column_id() - common::OB_APP_MIN_COLUMN_ID;} // true: primary key/hidden primary key(pk_increment/cluster_id/parition_id)/partitioned key of no-pk tables inline bool is_rowkey_column() const { return rowkey_position_ > 0; } // true: primary key/hidden primary key(pk_increment/cluster_id/parition_id) diff --git a/src/sql/code_generator/ob_static_engine_cg.cpp b/src/sql/code_generator/ob_static_engine_cg.cpp index a130496307..c6e0fb7e21 100644 --- a/src/sql/code_generator/ob_static_engine_cg.cpp +++ b/src/sql/code_generator/ob_static_engine_cg.cpp @@ -1530,7 +1530,7 @@ int ObStaticEngineCG::generate_recursive_union_all_spec(ObLogSet &op, ObRecursiv { const ObRawExpr* raw_expr = cycle_items.at(i).expr_; if (raw_expr->is_column_ref_expr()) { - uint64_t index = cycle_items.at(i).column_id_; + uint64_t index = cycle_items.at(i).column_id_ - OB_APP_MIN_COLUMN_ID; if (OB_FAIL(spec.cycle_by_col_lists_.push_back(index))) { LOG_WARN("Failed to add cycle by order", K(ret)); } diff --git a/src/sql/resolver/expr/ob_raw_expr.h b/src/sql/resolver/expr/ob_raw_expr.h index d6ef3a8056..32ab2312f1 100644 --- a/src/sql/resolver/expr/ob_raw_expr.h +++ b/src/sql/resolver/expr/ob_raw_expr.h @@ -2380,7 +2380,7 @@ public: inline void set_database_name(const common::ObString &db_name) { database_name_ = db_name; } inline const common::ObString &get_database_name() const { return database_name_; } inline common::ObString &get_database_name() { return database_name_; } - inline int64_t get_cte_generate_column_projector_offset() const { return get_column_id(); } + inline int64_t get_cte_generate_column_projector_offset() const { return get_column_id() - common::OB_APP_MIN_COLUMN_ID; } virtual void reset(); virtual bool inner_same_as(const ObRawExpr &expr, ObExprEqualCheckContext *check_context = NULL) const override; diff --git a/src/sql/resolver/ob_stmt_resolver.h b/src/sql/resolver/ob_stmt_resolver.h index 94ed7bfebc..c7bb339a5b 100644 --- a/src/sql/resolver/ob_stmt_resolver.h +++ b/src/sql/resolver/ob_stmt_resolver.h @@ -103,7 +103,7 @@ public: return ret_cid; } inline uint64_t generate_cte_table_id() { return params_.new_cte_tid_++;} - inline uint64_t generate_cte_column_base_id() { return common::OB_MIN_CTE_COLUMN_ID;} + inline uint64_t generate_cte_column_base_id() { return common::OB_APP_MIN_COLUMN_ID;} template T *create_stmt() { diff --git a/tools/deploy/mysql_test/test_suite/with_clause_mysql/r/mysql/basic_mysql.result b/tools/deploy/mysql_test/test_suite/with_clause_mysql/r/mysql/basic_mysql.result index 3b9331f341..631e8cb539 100644 --- a/tools/deploy/mysql_test/test_suite/with_clause_mysql/r/mysql/basic_mysql.result +++ b/tools/deploy/mysql_test/test_suite/with_clause_mysql/r/mysql/basic_mysql.result @@ -2585,4 +2585,26 @@ with cte as (select * from t1) select 1 from dual; | 1 | +---+ +with recursive cte1 as +( + select 1 as c1, 2 as c2, 3 as c3, 4 as c4, 5 as c5, 6 as c6, 7 as c7, 8 as c8, 9 as c9, 10 as c10, 11 as c11, 12 as c12 + union all + select c1+1,c2+1,c3+1,c4+1,c5+1,c6+1,c7+1,c8+1,c9+1,c10+1, c11+1, c12+1 from cte1 where c1 < 10 +) +select * from cte1; ++------+------+------+------+------+------+------+------+------+------+------+------+ +| c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c9 | c10 | c11 | c12 | ++------+------+------+------+------+------+------+------+------+------+------+------+ +| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | +| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | +| 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | +| 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | +| 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | +| 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | +| 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | +| 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | +| 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | +| 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | ++------+------+------+------+------+------+------+------+------+------+------+------+ + drop database cte_st; diff --git a/tools/deploy/mysql_test/test_suite/with_clause_mysql/t/basic_mysql.test b/tools/deploy/mysql_test/test_suite/with_clause_mysql/t/basic_mysql.test index 2f8eca0c45..716f47269f 100644 --- a/tools/deploy/mysql_test/test_suite/with_clause_mysql/t/basic_mysql.test +++ b/tools/deploy/mysql_test/test_suite/with_clause_mysql/t/basic_mysql.test @@ -755,5 +755,12 @@ delete from t1 where c1 = ( with cte (a) as (select max( c1 ) from t1 ) select * --echo ############################## with cte as (select * from t1) select 1 from dual; +with recursive cte1 as +( + select 1 as c1, 2 as c2, 3 as c3, 4 as c4, 5 as c5, 6 as c6, 7 as c7, 8 as c8, 9 as c9, 10 as c10, 11 as c11, 12 as c12 + union all + select c1+1,c2+1,c3+1,c4+1,c5+1,c6+1,c7+1,c8+1,c9+1,c10+1, c11+1, c12+1 from cte1 where c1 < 10 +) +select * from cte1; drop database cte_st; \ No newline at end of file