Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

增强子查询合并改写 || Enhanced subquery merge rewriting#2108

Open
sparkyen wants to merge 1 commit intooceanbase:masterfrom
sparkyen:subquery_combine
Open

增强子查询合并改写 || Enhanced subquery merge rewriting#2108
sparkyen wants to merge 1 commit intooceanbase:masterfrom
sparkyen:subquery_combine

Conversation

@sparkyen
Copy link

@sparkyensparkyen commentedSep 2, 2024
edited by github-actionsbot
Loading

Task Description

select * from t1where c1 in (select t2.c1 from t2)and c1 in (select t2.c1 from t2, t3 where t2.c2 = t3.c2;

可以做子查询合并改写

select * from t1where  c1 in (select t2.c1 from t2, t3 where t2.c2 = t3.c2;

Solution Description

根据 stmt 判断两个子查询结果不同值集合的包含关系后,再决策是否能做合并以及保留哪一个子查询

Passed Regressions

Upgrade Compatibility

Other Information

Release Note


Task Description

select * from t1where c1 in (select t2.c1 from t2)and c1 in (select t2.c1 from t2, t3 where t2.c2 = t3.c2;

You can merge and rewrite subqueries

select * from t1where c1 in (select t2.c1 from t2, t3 where t2.c2 = t3.c2;

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

@github-actionsgithub-actionsbot changed the title增强子查询合并改写增强子查询合并改写 || Enhanced subquery merge rewritingSep 2, 2024
@sparkyensparkyen reopened thisSep 2, 2024
@sparkyensparkyen reopened thisSep 2, 2024
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)))) {
Copy link
Contributor

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()) {
Copy link
Contributor

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()));
Copy link
Contributor

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(),
Copy link
Contributor

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)) {
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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 {
Copy link
Contributor

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,
Copy link
Contributor

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 ?

@sparkyensparkyenforce-pushed thesubquery_combine branch 2 times, most recently frombe24809 to4b6f718CompareSeptember 3, 2024 08:24
@sparkyensparkyen reopened thisSep 3, 2024
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

这里的逻辑有问题

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

1 more reviewer

@zzg19950727zzg19950727zzg19950727 left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@sparkyen@zzg19950727

Comments


[8]ページ先頭

©2009-2026 Movatter.jp