-
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/core: fix privilege check for update #10281
Conversation
Codecov Report
@@ Coverage Diff @@
## master #10281 +/- ##
===========================================
Coverage ? 77.6715%
===========================================
Files ? 411
Lines ? 85447
Branches ? 0
===========================================
Hits ? 66368
Misses ? 14118
Partials ? 4961 |
planner/core/logical_plan_builder.go
Outdated
@@ -157,7 +157,9 @@ func (b *PlanBuilder) buildResultSetNode(node ast.ResultSetNode) (p LogicalPlan, | |||
col.OrigTblName = col.TblName | |||
if x.AsName.L != "" { | |||
col.TblName = x.AsName | |||
col.DBName = model.NewCIStr("") | |||
if b.ctx.GetSessionVars().CurrentDB == col.DBName.L { |
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.
Could you add a comment here? Why should we check the currentDB name and set DBName to empty string?
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.
We can put an example here.
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.
I don't know why we set col.DBName = model.NewCIStr("")
here @zimulala
I should remove this line ... but it would make explain result (column name) change and affect many rows in the test
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.
OK, I'll remove this line... that's a better fix, anyway
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.
@tiancaiamao
I am not sure, I just changed the name of DBName
. This line of code was originally written like this.
PTAL @XuHuaiyu
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.
I guess the reason may be this:
When a table has an alias name, this "virtual table" does not belong to any database, we thought the DBName should be blank.
But I think it seems ok to keep the DBName here.
@@ -157,7 +157,6 @@ func (b *PlanBuilder) buildResultSetNode(node ast.ResultSetNode) (p LogicalPlan, | |||
col.OrigTblName = col.TblName | |||
if x.AsName.L != "" { | |||
col.TblName = x.AsName | |||
col.DBName = model.NewCIStr("") |
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 line is the real change in this PR
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.
why add an empty database name can fix the issue?
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.
One of the visitInfo record is
db="" table="t1" user="test"
It doesn't match any privilege record in the cache, so privilege check fail.
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.
The db name is not set correctly...
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.
The db name is set to "", and we should not set it to ""
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
├─TableReader_41 428.32 root data:Selection_40 | ||
│ └─Selection_40 428.32 cop eq(dt.bm, 0), eq(dt.pt, "ios"), gt(dt.t, 1478185592), not(isnull(dt.dic)) | ||
│ └─Selection_40 428.32 cop eq(test.dt.bm, 0), eq(test.dt.pt, "ios"), gt(test.dt.t, 1478185592), not(isnull(test.dt.dic)) | ||
│ └─TableScan_39 2000.00 cop table:dt, range:[0,+inf], keep order:false |
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 it dt
is alias name? If it's true, it is called dt
here, but it's called test.dt
on line 165. Is this a bit confused?
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.
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 mean we should use test.dt
in line 166? Currently, we do not print database name for PhysicalTableScan.
func (p *PhysicalTableScan) ExplainInfo() string {
buffer := bytes.NewBufferString("")
tblName := p.Table.Name.O
if p.TableAsName != nil && p.TableAsName.O != "" {
tblName = p.TableAsName.O
}
fmt.Fprintf(buffer, "table:%s", tblName)
...
}
If needed, we can print DBName as well, since it is recorded in PhysicalTableScan
.
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.
@eurekaka
No, I want to say if this situation will make you feel troubled.
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.
Oh I think it is not bothering since we merely meet queries where 2 tables share same name but from different databases.
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.
Got it.
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-all-tests |
What problem does this PR solve?
Login as test, run this update statement:
What is changed and how it works?
One of the visitInfo record is
It doesn't match any privilege record in the cache, so privilege check fail.
The bug is, db should not be "" here.
Check List
Tests
Related change