From 763a0866fa9af1cc8f986d106027c20aeb483ace Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Mon, 27 May 2024 09:10:15 +0800 Subject: [PATCH 1/8] planner: fix privilege for the view in the CTE Signed-off-by: Weizhen Wang --- .../core/issuetest/planner_issue_test.go | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/pkg/planner/core/issuetest/planner_issue_test.go b/pkg/planner/core/issuetest/planner_issue_test.go index 68abab69dc621..203d7e4ca9574 100644 --- a/pkg/planner/core/issuetest/planner_issue_test.go +++ b/pkg/planner/core/issuetest/planner_issue_test.go @@ -58,3 +58,133 @@ func TestIssue43461(t *testing.T) { require.NotEqual(t, is.Columns, ts.Columns) } + +func TestIssue49721(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec(` +CREATE TABLE pub_branch ( + id int(5) NOT NULL, + code varchar(12) NOT NULL, + type_id int(3) DEFAULT NULL, + name varchar(64) NOT NULL, + short_name varchar(32) DEFAULT NULL, + organ_code varchar(15) DEFAULT NULL, + parent_code varchar(12) DEFAULT NULL, + organ_layer tinyint(1) NOT NULL, + inputcode1 varchar(12) DEFAULT NULL, + inputcode2 varchar(12) DEFAULT NULL, + state tinyint(1) NOT NULL, + modify_empid int(9) NOT NULL, + modify_time datetime NOT NULL, + organ_level int(9) DEFAULT NULL, + address varchar(256) DEFAULT NULL, + db_user varchar(32) DEFAULT NULL, + db_password varchar(64) DEFAULT NULL, + org_no int(3) DEFAULT NULL, + ord int(5) DEFAULT NULL, + org_code_mpa varchar(10) DEFAULT NULL, + org_code_gb varchar(30) DEFAULT NULL, + wdchis_id int(5) DEFAULT NULL, + medins_code varchar(32) DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE KEY pub_barnch_unique (code), + KEY idx_pub_branch_parent (parent_code) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +`) + tk.MustExec(` +CREATE VIEW udc_branch_test ( + branch_id, + his_branch_id, + branch_code, + branch_name, + pid, + his_pid, + short_name, + inputcode1, + inputcode2, + org_no, + org_code, + org_level, + org_layer, + address, + state, + modify_by, + modify_time, + remark +) +AS +SELECT a.id AS branch_id, a.id AS his_branch_id, a.code AS branch_code, a.name AS branch_name + , a.id + 1000000 AS pid, id AS his_pid, a.short_name AS short_name + , a.inputcode1 AS inputcode1, a.inputcode2 AS inputcode2, a.id AS org_no, a.code AS org_code, a.organ_level AS org_level + , a.organ_layer AS org_layer, a.address AS address, a.state AS state, a.modify_empid AS modify_by, a.modify_time AS modify_time + , NULL AS remark +FROM pub_branch a +WHERE organ_layer = 4 +UNION ALL +SELECT a.id + 1000000 AS branch_id, a.id AS his_branch_id, a.code AS branch_code + , CONCAT(a.name, _UTF8MB4 '(中心)') AS branch_name + , ( + SELECT id AS id + FROM pub_branch a + WHERE organ_layer = 2 + AND state = 1 + LIMIT 1 + ) AS pid, id AS his_pid, a.short_name AS short_name, a.inputcode1 AS inputcode1, a.inputcode2 AS inputcode2 + , a.id AS org_no, a.code AS org_code, a.organ_level AS org_level, a.organ_layer AS org_layer, a.address AS address + , a.state AS state, 1 AS modify_by, a.modify_time AS modify_time, NULL AS remark +FROM pub_branch a +WHERE organ_layer = 4 +UNION ALL +SELECT a.id AS branch_id, a.id AS his_branch_id, a.code AS branch_code, a.name AS branch_name, NULL AS pid + , id AS his_pid, a.short_name AS short_name, a.inputcode1 AS inputcode1, a.inputcode2 AS inputcode2, a.id AS org_no + , a.code AS org_code, a.organ_level AS org_level, a.organ_layer AS org_layer, a.address AS address, a.state AS state + , a.modify_empid AS modify_by, a.modify_time AS modify_time, NULL AS remark +FROM pub_branch a +WHERE organ_layer = 2; +`) + tk.MustExec(` +CREATE TABLE udc_branch_temp ( + branch_id int(11) NOT NULL AUTO_INCREMENT COMMENT '', + his_branch_id varchar(20) DEFAULT NULL COMMENT '', + branch_code varchar(20) DEFAULT NULL COMMENT '', + branch_name varchar(64) NOT NULL COMMENT '', + pid int(11) DEFAULT NULL COMMENT '', + his_pid varchar(20) DEFAULT NULL COMMENT '', + short_name varchar(64) DEFAULT NULL COMMENT '', + inputcode1 varchar(12) DEFAULT NULL COMMENT '辅码1', + inputcode2 varchar(12) DEFAULT NULL COMMENT '辅码2', + org_no int(11) DEFAULT NULL COMMENT '', + org_code varchar(20) DEFAULT NULL COMMENT ',', + org_level tinyint(4) DEFAULT NULL COMMENT '', + org_layer tinyint(4) DEFAULT NULL COMMENT '', + address varchar(255) DEFAULT NULL COMMENT '机构地址', + state tinyint(4) NOT NULL DEFAULT '1' COMMENT '', + modify_by int(11) NOT NULL COMMENT '', + modify_time datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', + remark varchar(255) DEFAULT NULL COMMENT '备注', + PRIMARY KEY (branch_id) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=1030102 COMMENT=''; +`) + tk.MustQuery(` +SELECT res.* +FROM ( + ( + WITH RECURSIVE d AS ( + SELECT ub.* + FROM udc_branch_temp ub + WHERE ub.branch_id = 1000102 + UNION ALL + SELECT ub1.* + FROM udc_branch_temp ub1 + INNER JOIN d ON d.branch_id = ub1.pid + ) + SELECT d.* + FROM d + ) +) AS res +WHERE res.state != 2 +ORDER BY res.branch_id; +`) +} From bf111b1979cd9ddec385ac5c69d6aa44c97397c4 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 28 May 2024 15:25:44 +0800 Subject: [PATCH 2/8] statistics: make sure that get max table id Signed-off-by: Weizhen Wang --- pkg/planner/core/issuetest/planner_issue_test.go | 4 ++-- pkg/planner/core/logical_plan_builder.go | 5 +++++ pkg/privilege/privileges/privileges.go | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/planner/core/issuetest/planner_issue_test.go b/pkg/planner/core/issuetest/planner_issue_test.go index 203d7e4ca9574..3093e8db68355 100644 --- a/pkg/planner/core/issuetest/planner_issue_test.go +++ b/pkg/planner/core/issuetest/planner_issue_test.go @@ -173,11 +173,11 @@ FROM ( ( WITH RECURSIVE d AS ( SELECT ub.* - FROM udc_branch_temp ub + FROM udc_branch_test ub WHERE ub.branch_id = 1000102 UNION ALL SELECT ub1.* - FROM udc_branch_temp ub1 + FROM udc_branch_test ub1 INNER JOIN d ON d.branch_id = ub1.pid ) SELECT d.* diff --git a/pkg/planner/core/logical_plan_builder.go b/pkg/planner/core/logical_plan_builder.go index dec80f8d3e71f..ad41f63308232 100644 --- a/pkg/planner/core/logical_plan_builder.go +++ b/pkg/planner/core/logical_plan_builder.go @@ -74,6 +74,7 @@ import ( "github.com/pingcap/tidb/pkg/util/set" "github.com/pingcap/tidb/pkg/util/size" "github.com/pingcap/tipb/go-tipb" + "go.uber.org/zap" ) const ( @@ -5428,6 +5429,10 @@ func (b *PlanBuilder) BuildDataSourceFromView(ctx context.Context, dbName model. b.ctx.GetSessionVars().PlannerSelectBlockAsName.Store(originPlannerSelectBlockAsName) }() selectLogicalPlan, err := b.Build(ctx, selectNode) + if err != nil { + logutil.BgLogger().Error("fuck", zap.Error(err)) + } + if err != nil { if terror.ErrorNotEqual(err, plannererrors.ErrViewRecursive) && terror.ErrorNotEqual(err, plannererrors.ErrNoSuchTable) && diff --git a/pkg/privilege/privileges/privileges.go b/pkg/privilege/privileges/privileges.go index ecc028cd708f1..83b6ca29dbe7f 100644 --- a/pkg/privilege/privileges/privileges.go +++ b/pkg/privilege/privileges/privileges.go @@ -194,7 +194,9 @@ func (p *UserPrivileges) RequestVerificationWithUser(db, table, column string, p if SkipWithGrant { return true } - + if p.user == "" && p.host == "" { + return true + } if user == nil { return false } From bb08b2c9b1568cc7f248292755069c5cd347c395 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 28 May 2024 15:39:55 +0800 Subject: [PATCH 3/8] * Signed-off-by: Weizhen Wang --- pkg/planner/core/logical_plan_builder.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pkg/planner/core/logical_plan_builder.go b/pkg/planner/core/logical_plan_builder.go index ad41f63308232..9e4aaa55724ec 100644 --- a/pkg/planner/core/logical_plan_builder.go +++ b/pkg/planner/core/logical_plan_builder.go @@ -74,7 +74,6 @@ import ( "github.com/pingcap/tidb/pkg/util/set" "github.com/pingcap/tidb/pkg/util/size" "github.com/pingcap/tipb/go-tipb" - "go.uber.org/zap" ) const ( @@ -5429,17 +5428,14 @@ func (b *PlanBuilder) BuildDataSourceFromView(ctx context.Context, dbName model. b.ctx.GetSessionVars().PlannerSelectBlockAsName.Store(originPlannerSelectBlockAsName) }() selectLogicalPlan, err := b.Build(ctx, selectNode) - if err != nil { - logutil.BgLogger().Error("fuck", zap.Error(err)) - } - if err != nil { if terror.ErrorNotEqual(err, plannererrors.ErrViewRecursive) && terror.ErrorNotEqual(err, plannererrors.ErrNoSuchTable) && terror.ErrorNotEqual(err, plannererrors.ErrInternal) && terror.ErrorNotEqual(err, plannererrors.ErrFieldNotInGroupBy) && terror.ErrorNotEqual(err, plannererrors.ErrMixOfGroupFuncAndFields) && - terror.ErrorNotEqual(err, plannererrors.ErrViewNoExplain) { + terror.ErrorNotEqual(err, plannererrors.ErrViewNoExplain) && + terror.ErrorNotEqual(err, plannererrors.ErrNotSupportedYet) { err = plannererrors.ErrViewInvalid.GenWithStackByArgs(dbName.O, tableInfo.Name.O) } return nil, err From efd380795788933ac5d055f8920ec29ab1088c47 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 28 May 2024 15:50:56 +0800 Subject: [PATCH 4/8] * Signed-off-by: Weizhen Wang --- pkg/planner/core/issuetest/planner_issue_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/planner/core/issuetest/planner_issue_test.go b/pkg/planner/core/issuetest/planner_issue_test.go index 3093e8db68355..ba968f04c3b35 100644 --- a/pkg/planner/core/issuetest/planner_issue_test.go +++ b/pkg/planner/core/issuetest/planner_issue_test.go @@ -18,6 +18,7 @@ import ( "context" "testing" + "github.com/pingcap/tidb/pkg/errno" "github.com/pingcap/tidb/pkg/parser" "github.com/pingcap/tidb/pkg/planner" "github.com/pingcap/tidb/pkg/planner/core" @@ -167,7 +168,7 @@ CREATE TABLE udc_branch_temp ( PRIMARY KEY (branch_id) /*T![clustered_index] CLUSTERED */ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=1030102 COMMENT=''; `) - tk.MustQuery(` + tk.MustGetErrCode(` SELECT res.* FROM ( ( @@ -186,5 +187,5 @@ FROM ( ) AS res WHERE res.state != 2 ORDER BY res.branch_id; -`) +`, errno.ErrNotSupportedYet) } From 8aef8897e971fb08ec0be85064499b5fc2a81f09 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 28 May 2024 16:01:21 +0800 Subject: [PATCH 5/8] * Signed-off-by: Weizhen Wang --- pkg/planner/core/casetest/BUILD.bazel | 3 +- pkg/planner/core/casetest/plan_test.go | 131 ++++++++++++++++++ .../core/issuetest/planner_issue_test.go | 131 ------------------ pkg/privilege/privileges/privileges.go | 3 - 4 files changed, 133 insertions(+), 135 deletions(-) diff --git a/pkg/planner/core/casetest/BUILD.bazel b/pkg/planner/core/casetest/BUILD.bazel index 6c62171aef90d..2170c2e11d4e0 100644 --- a/pkg/planner/core/casetest/BUILD.bazel +++ b/pkg/planner/core/casetest/BUILD.bazel @@ -12,9 +12,10 @@ go_test( ], data = glob(["testdata/**"]), flaky = True, - shard_count = 24, + shard_count = 25, deps = [ "//pkg/domain", + "//pkg/errno", "//pkg/parser", "//pkg/parser/model", "//pkg/planner/core", diff --git a/pkg/planner/core/casetest/plan_test.go b/pkg/planner/core/casetest/plan_test.go index b1b4d3f7eeab5..63a536383a88f 100644 --- a/pkg/planner/core/casetest/plan_test.go +++ b/pkg/planner/core/casetest/plan_test.go @@ -19,6 +19,7 @@ import ( "strings" "testing" + "github.com/pingcap/tidb/pkg/errno" "github.com/pingcap/tidb/pkg/parser/model" "github.com/pingcap/tidb/pkg/planner/core" "github.com/pingcap/tidb/pkg/planner/core/base" @@ -330,3 +331,133 @@ func TestHandleEQAll(t *testing.T) { tk.MustQuery("select c2 from t2 where (c2 = all (select /*+ IGNORE_INDEX(t2, i1) */ c2 from t2))").Check(testkit.Rows()) tk.MustQuery("select c2 from t2 where (c2 = all (select /*+ use_INDEX(t2, i1) */ c2 from t2))").Check(testkit.Rows()) } + +func TestCTEErrNotSupportedYet(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec(` +CREATE TABLE pub_branch ( + id int(5) NOT NULL, + code varchar(12) NOT NULL, + type_id int(3) DEFAULT NULL, + name varchar(64) NOT NULL, + short_name varchar(32) DEFAULT NULL, + organ_code varchar(15) DEFAULT NULL, + parent_code varchar(12) DEFAULT NULL, + organ_layer tinyint(1) NOT NULL, + inputcode1 varchar(12) DEFAULT NULL, + inputcode2 varchar(12) DEFAULT NULL, + state tinyint(1) NOT NULL, + modify_empid int(9) NOT NULL, + modify_time datetime NOT NULL, + organ_level int(9) DEFAULT NULL, + address varchar(256) DEFAULT NULL, + db_user varchar(32) DEFAULT NULL, + db_password varchar(64) DEFAULT NULL, + org_no int(3) DEFAULT NULL, + ord int(5) DEFAULT NULL, + org_code_mpa varchar(10) DEFAULT NULL, + org_code_gb varchar(30) DEFAULT NULL, + wdchis_id int(5) DEFAULT NULL, + medins_code varchar(32) DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE KEY pub_barnch_unique (code), + KEY idx_pub_branch_parent (parent_code) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +`) + tk.MustExec(` +CREATE VIEW udc_branch_test ( + branch_id, + his_branch_id, + branch_code, + branch_name, + pid, + his_pid, + short_name, + inputcode1, + inputcode2, + org_no, + org_code, + org_level, + org_layer, + address, + state, + modify_by, + modify_time, + remark +) +AS +SELECT a.id AS branch_id, a.id AS his_branch_id, a.code AS branch_code, a.name AS branch_name + , a.id + 1000000 AS pid, id AS his_pid, a.short_name AS short_name + , a.inputcode1 AS inputcode1, a.inputcode2 AS inputcode2, a.id AS org_no, a.code AS org_code, a.organ_level AS org_level + , a.organ_layer AS org_layer, a.address AS address, a.state AS state, a.modify_empid AS modify_by, a.modify_time AS modify_time + , NULL AS remark +FROM pub_branch a +WHERE organ_layer = 4 +UNION ALL +SELECT a.id + 1000000 AS branch_id, a.id AS his_branch_id, a.code AS branch_code + , CONCAT(a.name, _UTF8MB4 '(中心)') AS branch_name + , ( + SELECT id AS id + FROM pub_branch a + WHERE organ_layer = 2 + AND state = 1 + LIMIT 1 + ) AS pid, id AS his_pid, a.short_name AS short_name, a.inputcode1 AS inputcode1, a.inputcode2 AS inputcode2 + , a.id AS org_no, a.code AS org_code, a.organ_level AS org_level, a.organ_layer AS org_layer, a.address AS address + , a.state AS state, 1 AS modify_by, a.modify_time AS modify_time, NULL AS remark +FROM pub_branch a +WHERE organ_layer = 4 +UNION ALL +SELECT a.id AS branch_id, a.id AS his_branch_id, a.code AS branch_code, a.name AS branch_name, NULL AS pid + , id AS his_pid, a.short_name AS short_name, a.inputcode1 AS inputcode1, a.inputcode2 AS inputcode2, a.id AS org_no + , a.code AS org_code, a.organ_level AS org_level, a.organ_layer AS org_layer, a.address AS address, a.state AS state + , a.modify_empid AS modify_by, a.modify_time AS modify_time, NULL AS remark +FROM pub_branch a +WHERE organ_layer = 2; +`) + tk.MustExec(` +CREATE TABLE udc_branch_temp ( + branch_id int(11) NOT NULL AUTO_INCREMENT COMMENT '', + his_branch_id varchar(20) DEFAULT NULL COMMENT '', + branch_code varchar(20) DEFAULT NULL COMMENT '', + branch_name varchar(64) NOT NULL COMMENT '', + pid int(11) DEFAULT NULL COMMENT '', + his_pid varchar(20) DEFAULT NULL COMMENT '', + short_name varchar(64) DEFAULT NULL COMMENT '', + inputcode1 varchar(12) DEFAULT NULL COMMENT '辅码1', + inputcode2 varchar(12) DEFAULT NULL COMMENT '辅码2', + org_no int(11) DEFAULT NULL COMMENT '', + org_code varchar(20) DEFAULT NULL COMMENT ',', + org_level tinyint(4) DEFAULT NULL COMMENT '', + org_layer tinyint(4) DEFAULT NULL COMMENT '', + address varchar(255) DEFAULT NULL COMMENT '机构地址', + state tinyint(4) NOT NULL DEFAULT '1' COMMENT '', + modify_by int(11) NOT NULL COMMENT '', + modify_time datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', + remark varchar(255) DEFAULT NULL COMMENT '备注', + PRIMARY KEY (branch_id) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=1030102 COMMENT=''; +`) + tk.MustGetErrCode(` +SELECT res.* +FROM ( + ( + WITH RECURSIVE d AS ( + SELECT ub.* + FROM udc_branch_test ub + WHERE ub.branch_id = 1000102 + UNION ALL + SELECT ub1.* + FROM udc_branch_test ub1 + INNER JOIN d ON d.branch_id = ub1.pid + ) + SELECT d.* + FROM d + ) +) AS res +WHERE res.state != 2 +ORDER BY res.branch_id; +`, errno.ErrNotSupportedYet) +} diff --git a/pkg/planner/core/issuetest/planner_issue_test.go b/pkg/planner/core/issuetest/planner_issue_test.go index ba968f04c3b35..68abab69dc621 100644 --- a/pkg/planner/core/issuetest/planner_issue_test.go +++ b/pkg/planner/core/issuetest/planner_issue_test.go @@ -18,7 +18,6 @@ import ( "context" "testing" - "github.com/pingcap/tidb/pkg/errno" "github.com/pingcap/tidb/pkg/parser" "github.com/pingcap/tidb/pkg/planner" "github.com/pingcap/tidb/pkg/planner/core" @@ -59,133 +58,3 @@ func TestIssue43461(t *testing.T) { require.NotEqual(t, is.Columns, ts.Columns) } - -func TestIssue49721(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(` -CREATE TABLE pub_branch ( - id int(5) NOT NULL, - code varchar(12) NOT NULL, - type_id int(3) DEFAULT NULL, - name varchar(64) NOT NULL, - short_name varchar(32) DEFAULT NULL, - organ_code varchar(15) DEFAULT NULL, - parent_code varchar(12) DEFAULT NULL, - organ_layer tinyint(1) NOT NULL, - inputcode1 varchar(12) DEFAULT NULL, - inputcode2 varchar(12) DEFAULT NULL, - state tinyint(1) NOT NULL, - modify_empid int(9) NOT NULL, - modify_time datetime NOT NULL, - organ_level int(9) DEFAULT NULL, - address varchar(256) DEFAULT NULL, - db_user varchar(32) DEFAULT NULL, - db_password varchar(64) DEFAULT NULL, - org_no int(3) DEFAULT NULL, - ord int(5) DEFAULT NULL, - org_code_mpa varchar(10) DEFAULT NULL, - org_code_gb varchar(30) DEFAULT NULL, - wdchis_id int(5) DEFAULT NULL, - medins_code varchar(32) DEFAULT NULL, - PRIMARY KEY (id), - UNIQUE KEY pub_barnch_unique (code), - KEY idx_pub_branch_parent (parent_code) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; -`) - tk.MustExec(` -CREATE VIEW udc_branch_test ( - branch_id, - his_branch_id, - branch_code, - branch_name, - pid, - his_pid, - short_name, - inputcode1, - inputcode2, - org_no, - org_code, - org_level, - org_layer, - address, - state, - modify_by, - modify_time, - remark -) -AS -SELECT a.id AS branch_id, a.id AS his_branch_id, a.code AS branch_code, a.name AS branch_name - , a.id + 1000000 AS pid, id AS his_pid, a.short_name AS short_name - , a.inputcode1 AS inputcode1, a.inputcode2 AS inputcode2, a.id AS org_no, a.code AS org_code, a.organ_level AS org_level - , a.organ_layer AS org_layer, a.address AS address, a.state AS state, a.modify_empid AS modify_by, a.modify_time AS modify_time - , NULL AS remark -FROM pub_branch a -WHERE organ_layer = 4 -UNION ALL -SELECT a.id + 1000000 AS branch_id, a.id AS his_branch_id, a.code AS branch_code - , CONCAT(a.name, _UTF8MB4 '(中心)') AS branch_name - , ( - SELECT id AS id - FROM pub_branch a - WHERE organ_layer = 2 - AND state = 1 - LIMIT 1 - ) AS pid, id AS his_pid, a.short_name AS short_name, a.inputcode1 AS inputcode1, a.inputcode2 AS inputcode2 - , a.id AS org_no, a.code AS org_code, a.organ_level AS org_level, a.organ_layer AS org_layer, a.address AS address - , a.state AS state, 1 AS modify_by, a.modify_time AS modify_time, NULL AS remark -FROM pub_branch a -WHERE organ_layer = 4 -UNION ALL -SELECT a.id AS branch_id, a.id AS his_branch_id, a.code AS branch_code, a.name AS branch_name, NULL AS pid - , id AS his_pid, a.short_name AS short_name, a.inputcode1 AS inputcode1, a.inputcode2 AS inputcode2, a.id AS org_no - , a.code AS org_code, a.organ_level AS org_level, a.organ_layer AS org_layer, a.address AS address, a.state AS state - , a.modify_empid AS modify_by, a.modify_time AS modify_time, NULL AS remark -FROM pub_branch a -WHERE organ_layer = 2; -`) - tk.MustExec(` -CREATE TABLE udc_branch_temp ( - branch_id int(11) NOT NULL AUTO_INCREMENT COMMENT '', - his_branch_id varchar(20) DEFAULT NULL COMMENT '', - branch_code varchar(20) DEFAULT NULL COMMENT '', - branch_name varchar(64) NOT NULL COMMENT '', - pid int(11) DEFAULT NULL COMMENT '', - his_pid varchar(20) DEFAULT NULL COMMENT '', - short_name varchar(64) DEFAULT NULL COMMENT '', - inputcode1 varchar(12) DEFAULT NULL COMMENT '辅码1', - inputcode2 varchar(12) DEFAULT NULL COMMENT '辅码2', - org_no int(11) DEFAULT NULL COMMENT '', - org_code varchar(20) DEFAULT NULL COMMENT ',', - org_level tinyint(4) DEFAULT NULL COMMENT '', - org_layer tinyint(4) DEFAULT NULL COMMENT '', - address varchar(255) DEFAULT NULL COMMENT '机构地址', - state tinyint(4) NOT NULL DEFAULT '1' COMMENT '', - modify_by int(11) NOT NULL COMMENT '', - modify_time datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', - remark varchar(255) DEFAULT NULL COMMENT '备注', - PRIMARY KEY (branch_id) /*T![clustered_index] CLUSTERED */ -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=1030102 COMMENT=''; -`) - tk.MustGetErrCode(` -SELECT res.* -FROM ( - ( - WITH RECURSIVE d AS ( - SELECT ub.* - FROM udc_branch_test ub - WHERE ub.branch_id = 1000102 - UNION ALL - SELECT ub1.* - FROM udc_branch_test ub1 - INNER JOIN d ON d.branch_id = ub1.pid - ) - SELECT d.* - FROM d - ) -) AS res -WHERE res.state != 2 -ORDER BY res.branch_id; -`, errno.ErrNotSupportedYet) -} diff --git a/pkg/privilege/privileges/privileges.go b/pkg/privilege/privileges/privileges.go index 83b6ca29dbe7f..6e03d4c3a64d8 100644 --- a/pkg/privilege/privileges/privileges.go +++ b/pkg/privilege/privileges/privileges.go @@ -194,9 +194,6 @@ func (p *UserPrivileges) RequestVerificationWithUser(db, table, column string, p if SkipWithGrant { return true } - if p.user == "" && p.host == "" { - return true - } if user == nil { return false } From 903e20f4e05c31ea00571b48dfc8150190d66519 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 28 May 2024 16:03:35 +0800 Subject: [PATCH 6/8] * Signed-off-by: Weizhen Wang --- pkg/privilege/privileges/privileges.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/privilege/privileges/privileges.go b/pkg/privilege/privileges/privileges.go index 6e03d4c3a64d8..83b6ca29dbe7f 100644 --- a/pkg/privilege/privileges/privileges.go +++ b/pkg/privilege/privileges/privileges.go @@ -194,6 +194,9 @@ func (p *UserPrivileges) RequestVerificationWithUser(db, table, column string, p if SkipWithGrant { return true } + if p.user == "" && p.host == "" { + return true + } if user == nil { return false } From cddb82284af5f7b72d80b9cefd0e738bcfbd9e82 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 28 May 2024 16:09:34 +0800 Subject: [PATCH 7/8] * Signed-off-by: Weizhen Wang --- pkg/privilege/privileges/privileges.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/privilege/privileges/privileges.go b/pkg/privilege/privileges/privileges.go index 83b6ca29dbe7f..e8be5a7072bfa 100644 --- a/pkg/privilege/privileges/privileges.go +++ b/pkg/privilege/privileges/privileges.go @@ -194,7 +194,7 @@ func (p *UserPrivileges) RequestVerificationWithUser(db, table, column string, p if SkipWithGrant { return true } - if p.user == "" && p.host == "" { + if user.Username == "" && user.Hostname == "" { return true } if user == nil { From 13a68a037e7e386146036506b9ca1d839616db3c Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 28 May 2024 16:10:01 +0800 Subject: [PATCH 8/8] * Signed-off-by: Weizhen Wang --- pkg/privilege/privileges/privileges.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/privilege/privileges/privileges.go b/pkg/privilege/privileges/privileges.go index e8be5a7072bfa..fb55a0b34a22f 100644 --- a/pkg/privilege/privileges/privileges.go +++ b/pkg/privilege/privileges/privileges.go @@ -194,12 +194,12 @@ func (p *UserPrivileges) RequestVerificationWithUser(db, table, column string, p if SkipWithGrant { return true } - if user.Username == "" && user.Hostname == "" { - return true - } if user == nil { return false } + if user.Username == "" && user.Hostname == "" { + return true + } // Skip check for INFORMATION_SCHEMA database. // See https://dev.mysql.com/doc/refman/5.7/en/information-schema.html