Skip to content

Commit

Permalink
fix show subscriptions (#1.1-dev) (#13584)
Browse files Browse the repository at this point in the history
fix show subscriptions (#1.1-dev)

Approved by: @sukki37, @iamlinjunhong, @qingxinhome, @heni02, @nnsgmsone, @ouyuanning
  • Loading branch information
YANGGMM authored Dec 20, 2023
1 parent 48d69d7 commit c3272df
Show file tree
Hide file tree
Showing 9 changed files with 647 additions and 560 deletions.
1 change: 1 addition & 0 deletions pkg/frontend/mysql_cmd_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2965,6 +2965,7 @@ func (mce *MysqlCmdExecutor) executeStmt(requestCtx context.Context,
err = moerr.NewInternalError(proc.Ctx, "only admin can create subscription")
return
}
st.Sql = sql
case *tree.DropDatabase:
err = inputNameIsInvalid(proc.Ctx, string(st.Name))
if err != nil {
Expand Down
1,158 changes: 605 additions & 553 deletions pkg/pb/plan/plan.pb.go

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions pkg/sql/compile/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/matrixorigin/matrixone/pkg/pb/lock"
"github.com/matrixorigin/matrixone/pkg/pb/plan"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/lockop"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/dialect"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
plan2 "github.com/matrixorigin/matrixone/pkg/sql/plan"
"github.com/matrixorigin/matrixone/pkg/sql/plan/function"
Expand Down Expand Up @@ -60,9 +59,7 @@ func (s *Scope) CreateDatabase(c *Compile) error {
return err
}

fmtCtx := tree.NewFmtCtx(dialect.MYSQL, tree.WithQuoteString(true))
c.stmt.Format(fmtCtx)
ctx := context.WithValue(c.ctx, defines.SqlKey{}, fmtCtx.String())
ctx := context.WithValue(c.ctx, defines.SqlKey{}, s.Plan.GetDdl().GetCreateDatabase().GetSql())
datType := ""
if s.Plan.GetDdl().GetCreateDatabase().SubscriptionOption != nil {
datType = catalog.SystemDBTypeSubscription
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/parsers/dialect/mysql/mysql_sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/sql/parsers/tree/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ type CreateDatabase struct {
Name Identifier
CreateOptions []CreateOption
SubscriptionOption *SubscriptionOption
Sql string
}

func (node *CreateDatabase) Format(ctx *FmtCtx) {
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/plan/build_ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,7 @@ func buildCreateDatabase(stmt *tree.CreateDatabase, ctx CompilerContext) (*Plan,
Publication: string(stmt.SubscriptionOption.Publication),
}
}
createDB.Sql = stmt.Sql

return &Plan{
Plan: &plan.Plan_Ddl{
Expand Down
1 change: 1 addition & 0 deletions proto/plan.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,7 @@ message CreateDatabase {
bool if_not_exists = 1;
string database = 2;
SubscriptionOption subscription_option = 3;
string sql = 4;
}

message AlterDatabase {
Expand Down
16 changes: 15 additions & 1 deletion test/distributed/cases/tenant/pub_sub1.result
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,18 @@ drop account test_tenant_2;
drop publication pubname1;
drop publication pubname2;
drop database db1;
set global enable_privilege_cache = on;
set global enable_privilege_cache = on;
create account `0b6d35cc_11ab_4da5_a5c5_c4cc09917c11` admin_name 'admin' identified by '111';
create account `62915dd9_d454_4b02_be16_0741d94b62cc` admin_name 'admin' identified by '111';
create database test;
use test;
create table tt(a int);
insert into tt values(1);
create publication mo_test_pub database test account `62915dd9_d454_4b02_be16_0741d94b62cc`;
create database mo_test_sub from `0b6d35cc_11ab_4da5_a5c5_c4cc09917c11` publication mo_test_pub;
show subscriptions;
Name From_Account
mo_test_sub 0b6d35cc_11ab_4da5_a5c5_c4cc09917c11
drop publication mo_test_pub;
drop account `0b6d35cc_11ab_4da5_a5c5_c4cc09917c11`;
drop account `62915dd9_d454_4b02_be16_0741d94b62cc`;
22 changes: 21 additions & 1 deletion test/distributed/cases/tenant/pub_sub1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,24 @@ drop publication pubname1;
drop publication pubname2;
drop database db1;

set global enable_privilege_cache = on;
set global enable_privilege_cache = on;


create account `0b6d35cc_11ab_4da5_a5c5_c4cc09917c11` admin_name 'admin' identified by '111';
create account `62915dd9_d454_4b02_be16_0741d94b62cc` admin_name 'admin' identified by '111';
-- @session:id=3&user=0b6d35cc_11ab_4da5_a5c5_c4cc09917c11:admin&password=111
create database test;
use test;
create table tt(a int);
insert into tt values(1);
create publication mo_test_pub database test account `62915dd9_d454_4b02_be16_0741d94b62cc`;
-- @session
-- @session:id=5&user=62915dd9_d454_4b02_be16_0741d94b62cc:admin&password=111
create database mo_test_sub from `0b6d35cc_11ab_4da5_a5c5_c4cc09917c11` publication mo_test_pub;
show subscriptions;
-- @session
-- @session:id=7&user=0b6d35cc_11ab_4da5_a5c5_c4cc09917c11:admin&password=111
drop publication mo_test_pub;
-- @session
drop account `0b6d35cc_11ab_4da5_a5c5_c4cc09917c11`;
drop account `62915dd9_d454_4b02_be16_0741d94b62cc`;

0 comments on commit c3272df

Please sign in to comment.