- Notifications
You must be signed in to change notification settings - Fork1.9k
增强子查询合并改写 || Enhanced subquery merge rewriting#2108
增强子查询合并改写 || Enhanced subquery merge rewriting#2108sparkyen wants to merge 1 commit intooceanbase:masterfrom
Conversation
| LOG_WARN("get unexpected null", K(first), K(second), K(ret)); | ||
| } else if (!first->is_select_stmt() || !second->is_select_stmt()) { | ||
| LOG_TRACE("failed to compare, not a select item", K(first->is_select_stmt()), K(second->is_select_stmt())); | ||
| } else if (FALSE_IT(first_sel = const_cast<ObSelectStmt*>(static_cast<const ObSelectStmt*>(first)))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
尽量不要用const_cast,如果这里需要普通指针,参数就不要指定const
| /*do nothing*/ | ||
| } else if (!first_sel->is_spj() || !second_sel->is_spj()) { | ||
| LOG_TRACE("failed to compare, check_any_all_containment can only be used with spj query"); | ||
| } else if (first_sel->get_from_item_size() == second_sel->get_from_item_size()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
select * from t1 where c1 in (select c1 from t2) and c1 in (select c1 from t2 where exists(select 1 from t3 where t2.c2 = t3.c2));
这个场景呢?
| ret = OB_ERR_UNEXPECTED; | ||
| LOG_WARN("get unexpected null", K(first), K(second), K(ret)); | ||
| } else if (!first->is_select_stmt() || !second->is_select_stmt()) { | ||
| LOG_TRACE("failed to compare, not a select item", K(first->is_select_stmt()), K(second->is_select_stmt())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
普通的trace日志一般不要写failed to,有歧义,可以写can not compare dml stmt
| true))) { | ||
| LOG_WARN("failed to check stmt containment", K(ret)); | ||
| LOG_WARN("failed to check stmt containment with same from_item size", K(ret)); | ||
| } else if (OB_FAIL(check_any_all_containment(first_query_ref->get_ref_stmt(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
这里会覆盖上一个case的relation,需要明确上一个case的relation为uncomparable才需要调用这个函数
| LOG_WARN("failed to compute unmatched conditions", K(ret)); | ||
| } | ||
| if (OB_FAIL(ret)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
直接else if接上去就可以了,不需要再if(OB_FAIL
| if (OB_SUCC(ret) && QueryRelation::QUERY_UNCOMPARABLE != relation) { | ||
| first_count = first_sel->get_condition_size(); | ||
| second_count = second_sel->get_condition_size(); | ||
| QueryRelation this_relation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
这个变量名改成:condition_relation吧
| if (OB_SUCC(ret) && QueryRelation::QUERY_UNCOMPARABLE != relation) { | ||
| ObSEArray<ObRawExpr*, 16> first_exprs; | ||
| ObSEArray<ObRawExpr*, 16> second_exprs; | ||
| QueryRelation this_relation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
这个变量名改成:select_relation
| } else if (QueryRelation::QUERY_EQUAL == this_relation) { | ||
| map_info.is_select_item_equal_ = true; | ||
| LOG_TRACE("succeed to check select item map", K(relation), K(map_info)); | ||
| } else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
这里显示设置一下:is_select_item_equal_=false,relation=uncompare
| return ret; | ||
| } | ||
| int ObTransformSubqueryCoalesce::check_any_all_containment(const ObDMLStmt *first, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
函数名改一下:check_select_expr_ndv_containment ?
be24809 to4b6f718Comparesrc/sql/rewrite/ob_stmt_comparer.cpp Outdated
| LOG_TRACE("succeed to check conditions map", K(relation), K(map_info)); | ||
| } else if (QueryRelation::QUERY_EQUAL == relation || | ||
| QueryRelation::QUERY_LEFT_SUBSET == condition_relation){ | ||
| if(QueryRelation::QUERY_LEFT_SUBSET == relation) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
这里的逻辑有问题
Uh oh!
There was an error while loading.Please reload this page.
Task Description
可以做子查询合并改写
Solution Description
根据 stmt 判断两个子查询结果不同值集合的包含关系后,再决策是否能做合并以及保留哪一个子查询
Passed Regressions
Upgrade Compatibility
Other Information
Release Note
Task Description
You can merge and rewrite subqueries
Solution Description
After judging the inclusion relationship of the different value sets of the two subquery results based on stmt, it then decides whether to merge and which subquery to retain.
Passed Regressions
Upgrade Compatibility
Other Information
Release Note