Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions go/test/endtoend/vtgate/unsharded/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,30 @@ func TestCallProcedure(t *testing.T) {
require.Contains(t, err.Error(), "OUT and INOUT parameters are not supported")
}

func TestTempTable(t *testing.T) {
defer cluster.PanicHandler(t)
ctx := context.Background()
vtParams := mysql.ConnParams{
Host: "localhost",
Port: clusterInstance.VtgateMySQLPort,
}
conn1, err := mysql.Connect(ctx, &vtParams)
require.NoError(t, err)
defer conn1.Close()

_ = exec(t, conn1, `create temporary table temp_t(id bigint primary key)`)
_ = exec(t, conn1, `insert into temp_t(id) values (1),(2),(3)`)
assertMatches(t, conn1, `select id from temp_t order by id`, `[[INT64(1)] [INT64(2)] [INT64(3)]]`)
assertMatches(t, conn1, `select count(table_id) from information_schema.innodb_temp_table_info`, `[[INT64(1)]]`)

conn2, err := mysql.Connect(ctx, &vtParams)
require.NoError(t, err)
defer conn2.Close()

assertMatches(t, conn2, `select count(table_id) from information_schema.innodb_temp_table_info`, `[[INT64(1)]]`)
execAssertError(t, conn2, `show create table temp_t`, `Table 'vt_customer.temp_t' doesn't exist (errno 1146) (sqlstate 42S02)`)
}

func exec(t *testing.T, conn *mysql.Conn, query string) *sqltypes.Result {
t.Helper()
qr, err := conn.ExecuteFetch(query, 1000, true)
Expand Down
431 changes: 222 additions & 209 deletions go/vt/proto/query/query.pb.go

Large diffs are not rendered by default.

61 changes: 57 additions & 4 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type (
DDLStatement interface {
iDDLStatement()
IsFullyParsed() bool
IsTemporary() bool
GetTable() TableName
GetAction() DDLAction
GetOptLike() *OptLike
Expand Down Expand Up @@ -421,6 +422,7 @@ type (

// DropTable represents a DROP TABLE statement.
DropTable struct {
Temp bool
FromTables TableNames
// The following fields are set if a DDL was fully analyzed.
IfExists bool
Expand All @@ -434,6 +436,7 @@ type (

// CreateTable represents a CREATE TABLE statement.
CreateTable struct {
Temp bool
Table TableName
IfNotExists bool
TableSpec *TableSpec
Expand Down Expand Up @@ -677,6 +680,46 @@ func (node *AlterView) IsFullyParsed() bool {
return true
}

// IsTemporary implements the DDLStatement interface
func (*TruncateTable) IsTemporary() bool {
return false
}

// IsTemporary implements the DDLStatement interface
func (*RenameTable) IsTemporary() bool {
return false
}

// IsTemporary implements the DDLStatement interface
func (node *CreateTable) IsTemporary() bool {
return node.Temp
}

// IsTemporary implements the DDLStatement interface
func (node *AlterTable) IsTemporary() bool {
return false
}

// IsTemporary implements the DDLStatement interface
func (node *CreateView) IsTemporary() bool {
return false
}

// IsTemporary implements the DDLStatement interface
func (node *DropView) IsTemporary() bool {
return false
}

// IsTemporary implements the DDLStatement interface
func (node *DropTable) IsTemporary() bool {
return node.Temp
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


// IsTemporary implements the DDLStatement interface
func (node *AlterView) IsTemporary() bool {
return false
}

// GetTable implements the DDLStatement interface
func (node *TruncateTable) GetTable() TableName {
return node.Table
Expand Down Expand Up @@ -3170,11 +3213,17 @@ func (node *AlterDatabase) Format(buf *TrackedBuffer) {

// Format formats the node.
func (node *CreateTable) Format(buf *TrackedBuffer) {
buf.WriteString("create ")
if node.Temp {
buf.WriteString("temporary ")
}
buf.WriteString("table ")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if node.IfNotExists {
buf.astPrintf(node, "create table if not exists %v", node.Table)
} else {
buf.astPrintf(node, "create table %v", node.Table)
buf.WriteString("if not exists ")
}
buf.astPrintf(node, "%v", node.Table)

if node.OptLike != nil {
buf.astPrintf(node, " %v", node.OptLike)
}
Expand Down Expand Up @@ -3239,11 +3288,15 @@ func (node *AlterView) Format(buf *TrackedBuffer) {

// Format formats the node.
func (node *DropTable) Format(buf *TrackedBuffer) {
temp := ""
if node.Temp {
temp = " temporary"
}
exists := ""
if node.IfExists {
exists = " if exists"
}
buf.astPrintf(node, "drop table%s %v", exists, node.FromTables)
buf.astPrintf(node, "drop%s table%s %v", temp, exists, node.FromTables)
}

// Format formats the node.
Expand Down
4 changes: 4 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,8 @@ var (
}, {
input: "create table a (b1 bool NOT NULL PRIMARY KEY, b2 boolean not null, KEY b2_idx(b))",
output: "create table a (\n\tb1 bool not null primary key,\n\tb2 boolean not null,\n\tKEY b2_idx (b)\n)",
}, {
input: "create temporary table a (\n\tid bigint\n)",
}, {
input: "CREATE TABLE pkai (id INT PRIMARY KEY AUTO_INCREMENT);",
output: "create table pkai (\n\tid INT auto_increment primary key\n)",
Expand Down Expand Up @@ -1263,6 +1265,8 @@ var (
}, {
input: "drop table if exists a,b restrict",
output: "drop table if exists a, b",
}, {
input: "drop temporary table if exists a, b",
}, {
input: "drop view if exists a cascade",
output: "drop view if exists a",
Expand Down
Loading