ddl: migrate part of ddl package code from Execute/ExecRestricted to safe API (1)#22670
ddl: migrate part of ddl package code from Execute/ExecRestricted to safe API (1)#22670ti-srebot merged 17 commits intopingcap:masterfrom
Conversation
Signed-off-by: AilinKid <314806019@qq.com>
ddl/util/util.go
Outdated
| recordDoneDeletedRangeSQL = `INSERT IGNORE INTO mysql.gc_delete_range_done SELECT * FROM mysql.gc_delete_range WHERE job_id = %? AND element_id = %?` | ||
| completeDeleteRangeSQL = `DELETE FROM mysql.gc_delete_range WHERE job_id = %? AND element_id = %?` | ||
| completeDeleteMultiRangesSQL = `DELETE FROM mysql.gc_delete_range WHERE job_id = %? AND element_id in (%?)` | ||
| updateDeleteRangeSQL = `UPDATE mysql.gc_delete_range SET start_key = "%?" WHERE job_id = %? AND element_id = %? AND start_key = "%?"` |
There was a problem hiding this comment.
Delete the quotes around %?.
ddl/column.go
Outdated
| sql := fmt.Sprintf("select 1 from `%s`.`%s` where %s limit 1;", schema.L, table.L, colsStr) | ||
| rows, _, err := ctx.(sqlexec.RestrictedSQLExecutor).ExecRestrictedSQL(sql) | ||
| sql := "select 1 from %n.%n where " + colsStr + " limit 1;" | ||
| stmt, err := ctx.(sqlexec.RestrictedSQLExecutor).ParseWithParams(context.Background(), sql, paramsList...) |
There was a problem hiding this comment.
It is not considered safe to use concat and ParseWithParams at the same time. Though this case is safe.
fmt.Sprintf(fmt.Sprintf("%s", "%s")) will report an error.
You may want to check this PR.
There was a problem hiding this comment.
good~
the PR link is not right
There was a problem hiding this comment.
I suggest that you can use fmt.Fprintf.
Signed-off-by: AilinKid <314806019@qq.com>
Signed-off-by: AilinKid <314806019@qq.com>
Signed-off-by: AilinKid <314806019@qq.com>
ddl/util/util.go
Outdated
| completeDeleteMultiRangesSQL := completeDeleteMultiRangesSQLPrefix + idList + completeDeleteMultiRangesSQLSuffix | ||
| _, err := ctx.(sqlexec.SQLExecutor).ExecuteInternal(context.TODO(), completeDeleteMultiRangesSQL, paramIDs...) | ||
| var buf strings.Builder | ||
| _, err := fmt.Fprintf(&buf, completeDeleteMultiRangesSQL, idList) |
There was a problem hiding this comment.
Just let you know, we have fmt.Fprintf in our errcheck_ignore lists. And I agreed with that. fmt.Fprintf can not throw error on valid input, unless OOM. So you do not need to check that error.
BTW, You could use Fprintf to concat idList & nameList too.
|
/run-all-tests |
|
/run-integration-copr-test |
|
ptal @tiancaiamao |
|
LGTM |
|
/merge |
|
/run-all-tests |
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
|
cherry pick to release-5.0-rc in PR #22928 |
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
|
cherry pick to release-4.0 in PR #22929 |
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
|
cherry pick to release-3.0 in PR #22930 |
…safe API (1) (pingcap#22670) Signed-off-by: AilinKid <314806019@qq.com>
Signed-off-by: AilinKid 314806019@qq.com
What problem does this PR solve?
Issue Number: part close #pingcap/tidb-test#1152
What is changed and how it works?
What's Changed:
Migrate part of code in ddl package from using Execute/ExecRestricted to safe API
Related changes
pingcap/docs/pingcap/docs-cn:Check List
Tests
Release note