-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
planner: fill missing origin table name for DEFAULT()
function
#12550
Conversation
5dd5f28
to
b2297a3
Compare
Codecov Report
@@ Coverage Diff @@
## master #12550 +/- ##
===========================================
Coverage 80.0488% 80.0488%
===========================================
Files 473 473
Lines 116725 116725
===========================================
Hits 93437 93437
Misses 15960 15960
Partials 7328 7328 |
In TiDB
In MySQL
i.e. Still use `originalTableName doesn't solve the key issue. |
Also, if there's a table |
This PR need more discussion, The time is not ripe. So we close it. |
create table t2(f1 int(11) default 11);
insert into t2 value ();
select default(f1) from (select * from t2) t1; # <-- 11
select default(f1) from (select * from (select * from t2) t1 ) t1; # <-- Error 1146: Table 'test.t1' doesn't exist |
# Conflicts: # expression/expression.go
/run-all-tests |
2f5b21d
to
3ebc096
Compare
@wjhuang2016, @tangenta, @winoros, @wshwsh12, PTAL. |
@wjhuang2016, @tangenta, @winoros, PTAL. |
/run-all-tests |
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.
lgtm
/run-integration-common-test |
@winoros thanks~ |
cherry pick to release-3.1 failed |
cherry pick to release-3.0 failed |
cherry pick to release-2.1 failed |
What problem does this PR solve?
Fix #12471, #13189, #13390
What is changed and how it works?
The reason why we get the unexpect error
Field (a) doesn't have a default value
is that we missing the origin table name when rewrite the expression containsDEFAULT()
function.In detail, when we assign value to column
a
byset a = default(b)
, TiDB will rewrite the assignment expressiondefault(b)
. When it execute toevalDefaultExpr
, It will do some check:tidb/planner/core/expression_rewriter.go
Lines 1508 to 1514 in 41ac571
If the
OrigTblName
inlogicalplan.Schema
is empty, TiDB think the columnname referenced by
DEFAULT()
function is not a real column name (it's anAsName
), so it throw the errorField (a) doesn't have a default value
.To resolve this issue, we should fill the missing origin table name when build the logicPlan, after that, rewrite the assignment expression.
Another issue is TiDB cannot get the column name of subquery's subquery (#13390).To resolve this issue, we should keep the original table name of the subquery as far as possible. When
buildResultNode()
, if theorigTableName
in logic plan is not empty, we should keep it. otherwise, we should replace the emptyorigTableName
by thetableName
.Check List
Tests
Side effects