-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[chore](nereids) Added compatibility with mysql alias conflict #38104
Conversation
Thank you for your contribution to Apache Doris. Since 2024-03-18, the Document has been moved to doris-website. |
buildall |
sql """ DROP TABLE IF EXISTS `test3` """ | ||
|
||
sql """ | ||
CREATE TABLE `test1` ( |
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.
test1
table conflict to nereids_syntax_p0/test_limit.groovy
, please rename to other table name, e.g. test_alias_tbl1
, test_alias_tbl2
// get table name | ||
} else if (child instanceof LogicalFilter) { | ||
Plan grandChild = child.children().get(0); | ||
if (grandChild instanceof LogicalOlapScan) { |
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.
you should support other table type, for example, LogicalFileScan
for hive table, so LogicalCatalogRelation
is more suitable
@@ -507,6 +508,31 @@ private LogicalJoin<Plan, Plan> bindJoin(MatchingContext<LogicalJoin<Plan, Plan> | |||
LogicalJoin<Plan, Plan> join = ctx.root; | |||
CascadesContext cascadesContext = ctx.cascadesContext; | |||
|
|||
Set<String> tableNames = new HashSet<>(); | |||
List<Plan> children = join.children(); | |||
for (Plan child : children) { |
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.
this seems only check one level alias, can you support check conflict names between multiple level?
sql "select * from (select * from test1) a, (select * from test1) a;" | ||
exception "Not unique table/alias: 'a'" | ||
} | ||
|
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.
Add more cases
multi_sql """
DROP TABLE IF EXISTS test_alias_tbl1;
CREATE TABLE IF NOT EXISTS `test_alias_tbl1 ` (
`id` varchar(64) NULL
)
DISTRIBUTED BY HASH(`id`)
PROPERTIES (
"replication_num"="1"
);
"""
test {
sql "select * from test_alias_tbl1, test_alias_tbl1 b, test_alias_tbl1 c, test_alias_tbl1"
exception "Not unique table/alias: 'test_alias_tbl1'"
}
test {
sql """select * from test_alias_tbl1
join test_alias_tbl1 b on test_alias_tbl1.id = b.id
join test_alias_tbl1 c on b.id = c.id
join test_alias_tbl1 on true"""
exception "Not unique table/alias: 'test_alias_tbl1'"
}
run buildall |
run buildall |
nest relation detail
nest relation detail
// Recursive method to check for duplicate table names or aliases | ||
private void checkPlan(Plan plan, Set<String> tableNames) throws AnalysisException { | ||
if (plan instanceof LogicalSubQueryAlias) { | ||
LogicalSubQueryAlias subQueryAlias = (LogicalSubQueryAlias) plan; | ||
String alias = subQueryAlias.getAlias(); | ||
|
||
if (!tableNames.add(alias)) { | ||
throw new AnalysisException("Not unique table/alias: '" + alias + "'"); | ||
} | ||
|
||
} else if (plan instanceof LogicalCatalogRelation) { | ||
LogicalCatalogRelation relation = (LogicalCatalogRelation) plan; | ||
String tableName = relation.getTable().getName(); | ||
|
||
|
||
if (!tableNames.add(tableName)) { | ||
throw new AnalysisException("Not unique table/alias: '" + tableName + "'"); | ||
} | ||
} else { | ||
// Recursively check the children of the current plan | ||
for (Plan child : plan.children()) { | ||
checkPlan(child, tableNames); | ||
} | ||
} | ||
} | ||
|
||
|
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.
how about refactor to
private void checkConflictAlias(Plan plan) {
Set<String> existsTableNames = Sets.newLinkedHashSet();
Consumer<String> checkAlias = tableAliasName -> {
if (!existsTableNames.add(tableAliasName)) {
throw new AnalysisException("Not unique table/alias: '" + tableAliasName + "'");
}
};
boolean stopCheckChildren = true;
plan.foreach(p -> {
if (p instanceof LogicalSubQueryAlias) {
checkAlias.accept(((LogicalSubQueryAlias<?>) p).getAlias());
return stopCheckChildren;
} else if (p instanceof LogicalCatalogRelation) {
TableIf table = ((LogicalCatalogRelation) p).getTable();
checkAlias.accept(table.getName());
return stopCheckChildren;
} else {
return !stopCheckChildren;
}
});
}
run buildall |
run buildall |
TPC-H: Total hot run time: 39863 ms
|
TPC-DS: Total hot run time: 172241 ms
|
ClickBench: Total hot run time: 30.51 s
|
run buildall |
run buildall |
TPC-H: Total hot run time: 39332 ms
|
TPC-DS: Total hot run time: 173539 ms
|
ClickBench: Total hot run time: 30.42 s
|
run buildall |
run buildall |
TPC-H: Total hot run time: 39276 ms
|
run buildall |
TPC-H: Total hot run time: 39432 ms
|
TPC-DS: Total hot run time: 172368 ms
|
ClickBench: Total hot run time: 31.19 s
|
PR approved by at least one committer and no changes requested. |
throw table name/alias conflict exception to keep same behavior with mysql for example: ```sql select * from test.a b, test.b ``` error: ``` Not unique table/alias: 'b' ```
throw table name/alias conflict exception to keep same behavior with mysql for example: ```sql select * from test.a b, test.b ``` error: ``` Not unique table/alias: 'b' ```
… (#38440) throw table name/alias conflict exception to keep same behavior with mysql for example: ```sql select * from test.a b, test.b ``` error: ``` Not unique table/alias: 'b' ```
…e#38104) throw table name/alias conflict exception to keep same behavior with mysql for example: ```sql select * from test.a b, test.b ``` error: ``` Not unique table/alias: 'b' ```
Proposed changes
throw table name/alias conflict exception to keep same behavior with mysql
for example:
error: