Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
20a00ae
feat: start adding parsing support for create procedure
GuptaManan100 Mar 11, 2025
7b9eac4
feat: add parsing support for basics of create procedure
GuptaManan100 Mar 11, 2025
dc6ad2e
feat: add begin end block statement
GuptaManan100 Mar 11, 2025
5948fd5
feat: add parsing support for if block
GuptaManan100 Mar 11, 2025
322038f
feat: rewrite no scope to session scope
GuptaManan100 Mar 12, 2025
6aef510
feat: add parsing for declare variable and add tests for it
GuptaManan100 Mar 12, 2025
86bc8e7
feat: fix normalization of NoScope
GuptaManan100 Mar 12, 2025
1db7393
feat: remove setDDL from views parsing
GuptaManan100 Mar 12, 2025
71b6855
feat: add parsing for declare handler statements
GuptaManan100 Mar 13, 2025
4db27ca
feat: allow no scope in vttablet too
GuptaManan100 Mar 13, 2025
d0ffe66
feat: fix plan output to account for found being a keyword
GuptaManan100 Mar 13, 2025
78ba65a
feat: add parsing for select into as well
GuptaManan100 Mar 13, 2025
790f786
feat: implement signal and declare condition commands
GuptaManan100 Mar 13, 2025
93ec52e
feat: fix tests post parser changes
GuptaManan100 Mar 17, 2025
62ea2c0
feat: add the capability to parse multiple statements in the parser a…
GuptaManan100 Mar 17, 2025
9dce1b3
feat: add function to ignore empty statements after parsing and fix t…
GuptaManan100 Mar 18, 2025
324fa32
feat: add more tests for split statements and make it check if the st…
GuptaManan100 Mar 20, 2025
0567061
feat: fix test expectations
GuptaManan100 Mar 20, 2025
cf353ca
feat: fix test expectations
GuptaManan100 Mar 20, 2025
7b0f670
Merge remote-tracking branch 'upstream/main' into create-procedure
GuptaManan100 Mar 24, 2025
0d49a30
feat: improve performance of split statements by only requiring parsi…
GuptaManan100 Mar 24, 2025
fa771f5
test: fix test to run create procedures through ApplySchema and Vtgate
GuptaManan100 Mar 24, 2025
2bb0d1f
feat: fix ddl parsing to allow qualifiers and add planning support
GuptaManan100 Mar 24, 2025
e8960cd
test: fix test expectaitons
GuptaManan100 Mar 24, 2025
623b76f
test: add plan tests for create procedure statements
GuptaManan100 Mar 24, 2025
bffc6c6
Merge remote-tracking branch 'upstream/main' into create-procedure
GuptaManan100 Mar 25, 2025
176bad8
Merge remote-tracking branch 'upstream/main' into create-procedure
GuptaManan100 Mar 25, 2025
b6880d7
feat: address review comments by changing compound statements to a st…
GuptaManan100 Mar 28, 2025
c12ccb7
feat: address review comments
GuptaManan100 Mar 31, 2025
bd49991
feat: add parsing for drop procedure
GuptaManan100 Mar 31, 2025
f290c53
feat: add support for drop procedure
GuptaManan100 Mar 31, 2025
58e1ee0
feat: added a test for a single unsharded keyspace
GuptaManan100 Apr 1, 2025
cc2b1f7
test: remove couple of lines
GuptaManan100 Apr 1, 2025
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
2 changes: 1 addition & 1 deletion go/test/endtoend/mysqlserver/mysql_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestMultiStatement(t *testing.T) {

_, err = db.QueryContext(ctx, "SELECT 1; SELECT 2; SELECT 3")
require.NotNilf(t, err, "error expected, got nil error")
assert.Containsf(t, err.Error(), "syntax error", "expected syntax error, got %v", err)
assert.Containsf(t, err.Error(), "Error 1149 (42000): Expected a single statement", "expected error, got %v", err)
}

// TestLargeComment add large comment in insert stmt and validate the insert process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ package scheduler

import (
"context"
"errors"
"flag"
"fmt"
"io"
"math/rand/v2"
"os"
"path"
Expand Down Expand Up @@ -130,13 +128,9 @@ deletesAttempts=%d, deletesFailures=%d, deletesNoops=%d, deletes=%d,
func parseTableName(t *testing.T, sql string) (tableName string) {
// ddlStatement could possibly be composed of multiple DDL statements
parser := sqlparser.NewTestParser()
tokenizer := parser.NewStringTokenizer(sql)
for {
stmt, err := sqlparser.ParseNextStrictDDL(tokenizer)
if err != nil && errors.Is(err, io.EOF) {
break
}
require.NoErrorf(t, err, "parsing sql: [%v]", sql)
stmts, err := parser.ParseMultiple(sql)
require.NoError(t, err)
for _, stmt := range stmts {
ddlStmt, ok := stmt.(sqlparser.DDLStatement)
require.True(t, ok)
tableName = ddlStmt.GetTable().Name.String()
Expand Down
18 changes: 9 additions & 9 deletions go/test/endtoend/transaction/twopc/twopc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestDTCommit(t *testing.T) {
utils.Exec(t, conn, "begin")
utils.Exec(t, conn, "insert into twopc_user(id, name) values(7,'foo')")
utils.Exec(t, conn, "insert into twopc_user(id, name) values(8,'bar')")
utils.Exec(t, conn, `set @@time_zone="+10:30"`)
utils.Exec(t, conn, `set time_zone="+10:30"`)
utils.Exec(t, conn, "insert into twopc_user(id, name) values(9,'baz')")
utils.Exec(t, conn, "insert into twopc_user(id, name) values(10,'apa')")
utils.Exec(t, conn, "commit")
Expand Down Expand Up @@ -125,16 +125,16 @@ func TestDTCommit(t *testing.T) {
"delete:[VARCHAR(\"dtid-1\") VARCHAR(\"PREPARE\")]",
},
"ks.redo_statement:-40": {
"insert:[VARCHAR(\"dtid-1\") INT64(1) BLOB(\"set @@time_zone = '+10:30'\")]",
"insert:[VARCHAR(\"dtid-1\") INT64(1) BLOB(\"set time_zone = '+10:30'\")]",
"insert:[VARCHAR(\"dtid-1\") INT64(2) BLOB(\"insert into twopc_user(id, `name`) values (10, 'apa')\")]",
"delete:[VARCHAR(\"dtid-1\") INT64(1) BLOB(\"set @@time_zone = '+10:30'\")]",
"delete:[VARCHAR(\"dtid-1\") INT64(1) BLOB(\"set time_zone = '+10:30'\")]",
"delete:[VARCHAR(\"dtid-1\") INT64(2) BLOB(\"insert into twopc_user(id, `name`) values (10, 'apa')\")]",
},
"ks.redo_statement:40-80": {
"insert:[VARCHAR(\"dtid-1\") INT64(1) BLOB(\"insert into twopc_user(id, `name`) values (8, 'bar')\")]",
"insert:[VARCHAR(\"dtid-1\") INT64(2) BLOB(\"set @@time_zone = '+10:30'\")]",
"insert:[VARCHAR(\"dtid-1\") INT64(2) BLOB(\"set time_zone = '+10:30'\")]",
"delete:[VARCHAR(\"dtid-1\") INT64(1) BLOB(\"insert into twopc_user(id, `name`) values (8, 'bar')\")]",
"delete:[VARCHAR(\"dtid-1\") INT64(2) BLOB(\"set @@time_zone = '+10:30'\")]",
"delete:[VARCHAR(\"dtid-1\") INT64(2) BLOB(\"set time_zone = '+10:30'\")]",
},
"ks.twopc_user:-40": {
`insert:[INT64(10) VARCHAR("apa")]`,
Expand Down Expand Up @@ -172,9 +172,9 @@ func TestDTCommit(t *testing.T) {
"delete:[VARCHAR(\"dtid-2\") VARCHAR(\"PREPARE\")]",
},
"ks.redo_statement:40-80": {
"insert:[VARCHAR(\"dtid-2\") INT64(1) BLOB(\"set @@time_zone = '+10:30'\")]",
"insert:[VARCHAR(\"dtid-2\") INT64(1) BLOB(\"set time_zone = '+10:30'\")]",
"insert:[VARCHAR(\"dtid-2\") INT64(2) BLOB(\"update twopc_user set `name` = 'newfoo' where id = 8 limit 10001 /* INT64 */\")]",
"delete:[VARCHAR(\"dtid-2\") INT64(1) BLOB(\"set @@time_zone = '+10:30'\")]",
"delete:[VARCHAR(\"dtid-2\") INT64(1) BLOB(\"set time_zone = '+10:30'\")]",
"delete:[VARCHAR(\"dtid-2\") INT64(2) BLOB(\"update twopc_user set `name` = 'newfoo' where id = 8 limit 10001 /* INT64 */\")]",
},
"ks.twopc_user:40-80": {"update:[INT64(8) VARCHAR(\"newfoo\")]"},
Expand Down Expand Up @@ -205,9 +205,9 @@ func TestDTCommit(t *testing.T) {
"delete:[VARCHAR(\"dtid-3\") VARCHAR(\"PREPARE\")]",
},
"ks.redo_statement:-40": {
"insert:[VARCHAR(\"dtid-3\") INT64(1) BLOB(\"set @@time_zone = '+10:30'\")]",
"insert:[VARCHAR(\"dtid-3\") INT64(1) BLOB(\"set time_zone = '+10:30'\")]",
"insert:[VARCHAR(\"dtid-3\") INT64(2) BLOB(\"delete from twopc_user where id = 10 limit 10001 /* INT64 */\")]",
"delete:[VARCHAR(\"dtid-3\") INT64(1) BLOB(\"set @@time_zone = '+10:30'\")]",
"delete:[VARCHAR(\"dtid-3\") INT64(1) BLOB(\"set time_zone = '+10:30'\")]",
"delete:[VARCHAR(\"dtid-3\") INT64(2) BLOB(\"delete from twopc_user where id = 10 limit 10001 /* INT64 */\")]",
},
"ks.twopc_user:-40": {"delete:[INT64(10) VARCHAR(\"apa\")]"},
Expand Down
140 changes: 62 additions & 78 deletions go/test/endtoend/vtgate/unsharded/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (

var (
clusterInstance *cluster.LocalProcessCluster
vtParams mysql.ConnParams
cell = "zone1"
hostname = "localhost"
KeyspaceName = "customer"
Expand All @@ -56,7 +57,43 @@ CREATE TABLE t1 (
CREATE TABLE allDefaults (
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255)
) ENGINE=Innodb;`
) ENGINE=Innodb;

CREATE PROCEDURE sp_insert()
BEGIN
insert into allDefaults () values ();
END;

CREATE PROCEDURE sp_delete()
BEGIN
delete from allDefaults;
END;

CREATE PROCEDURE sp_multi_dml()
BEGIN
insert into allDefaults () values ();
delete from allDefaults;
END;

CREATE PROCEDURE sp_variable()
BEGIN
insert into allDefaults () values ();
SELECT min(id) INTO @myvar FROM allDefaults;
DELETE FROM allDefaults WHERE id = @myvar;
END;

CREATE PROCEDURE sp_select()
BEGIN
SELECT * FROM allDefaults;
END;

CREATE PROCEDURE sp_all()
BEGIN
insert into allDefaults () values ();
select * from allDefaults;
delete from allDefaults;
END;`

VSchema = `
{
"sharded": false,
Expand Down Expand Up @@ -98,41 +135,6 @@ CREATE TABLE allDefaults (
`

createProcSQL = []string{`
CREATE PROCEDURE sp_insert()
BEGIN
insert into allDefaults () values ();
END;
`, `
CREATE PROCEDURE sp_delete()
BEGIN
delete from allDefaults;
END;
`, `
CREATE PROCEDURE sp_multi_dml()
BEGIN
insert into allDefaults () values ();
delete from allDefaults;
END;
`, `
CREATE PROCEDURE sp_variable()
BEGIN
insert into allDefaults () values ();
SELECT min(id) INTO @myvar FROM allDefaults;
DELETE FROM allDefaults WHERE id = @myvar;
END;
`, `
CREATE PROCEDURE sp_select()
BEGIN
SELECT * FROM allDefaults;
END;
`, `
CREATE PROCEDURE sp_all()
BEGIN
insert into allDefaults () values ();
select * from allDefaults;
delete from allDefaults;
END;
`, `
CREATE PROCEDURE in_parameter(IN val int)
BEGIN
insert into allDefaults(id) values(val);
Expand Down Expand Up @@ -177,8 +179,20 @@ func TestMain(m *testing.M) {
return 1
}

primaryTablet := clusterInstance.Keyspaces[0].Shards[0].PrimaryTablet().VttabletProcess
if err := primaryTablet.QueryTabletMultiple(createProcSQL, KeyspaceName, true); err != nil {
// Also check we can create procedures through the vtgate.
vtParams = mysql.ConnParams{
Host: "localhost",
Port: clusterInstance.VtgateMySQLPort,
}
conn, err := mysql.Connect(context.Background(), &vtParams)
if err != nil {
log.Fatal(err.Error())
return 1
}
defer conn.Close()

err = runCreateProcedures(conn)
if err != nil {
log.Fatal(err.Error())
return 1
}
Expand All @@ -188,14 +202,20 @@ func TestMain(m *testing.M) {
os.Exit(exitCode)
}

func runCreateProcedures(conn *mysql.Conn) error {
for _, sql := range createProcSQL {
_, err := conn.ExecuteFetch(sql, 1000, true)
if err != nil {
return err
}
}
return nil
}

func TestSelectIntoAndLoadFrom(t *testing.T) {
// Test is skipped because it requires secure-file-priv variable to be set to not NULL or empty.
t.Skip()
ctx := context.Background()
vtParams := mysql.ConnParams{
Host: "localhost",
Port: clusterInstance.VtgateMySQLPort,
}
conn, err := mysql.Connect(ctx, &vtParams)
require.Nil(t, err)
defer conn.Close()
Expand Down Expand Up @@ -226,10 +246,6 @@ func TestSelectIntoAndLoadFrom(t *testing.T) {

func TestEmptyStatement(t *testing.T) {
ctx := context.Background()
vtParams := mysql.ConnParams{
Host: "localhost",
Port: clusterInstance.VtgateMySQLPort,
}
conn, err := mysql.Connect(ctx, &vtParams)
require.Nil(t, err)
defer conn.Close()
Expand All @@ -242,10 +258,6 @@ func TestEmptyStatement(t *testing.T) {

func TestTopoDownServingQuery(t *testing.T) {
ctx := context.Background()
vtParams := mysql.ConnParams{
Host: "localhost",
Port: clusterInstance.VtgateMySQLPort,
}
conn, err := mysql.Connect(ctx, &vtParams)
require.Nil(t, err)
defer conn.Close()
Expand All @@ -261,10 +273,6 @@ func TestTopoDownServingQuery(t *testing.T) {

func TestInsertAllDefaults(t *testing.T) {
ctx := context.Background()
vtParams := mysql.ConnParams{
Host: "localhost",
Port: clusterInstance.VtgateMySQLPort,
}
conn, err := mysql.Connect(ctx, &vtParams)
require.NoError(t, err)
defer conn.Close()
Expand All @@ -275,10 +283,6 @@ func TestInsertAllDefaults(t *testing.T) {

func TestDDLUnsharded(t *testing.T) {
ctx := context.Background()
vtParams := mysql.ConnParams{
Host: "localhost",
Port: clusterInstance.VtgateMySQLPort,
}
conn, err := mysql.Connect(ctx, &vtParams)
require.NoError(t, err)
defer conn.Close()
Expand Down Expand Up @@ -341,10 +345,6 @@ func TestCallProcedure(t *testing.T) {

func TestTempTable(t *testing.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()
Expand All @@ -365,10 +365,6 @@ func TestTempTable(t *testing.T) {

func TestReservedConnDML(t *testing.T) {
ctx := context.Background()
vtParams := mysql.ConnParams{
Host: "localhost",
Port: clusterInstance.VtgateMySQLPort,
}
conn, err := mysql.Connect(ctx, &vtParams)
require.NoError(t, err)
defer conn.Close()
Expand All @@ -387,10 +383,6 @@ func TestReservedConnDML(t *testing.T) {

func TestNumericPrecisionScale(t *testing.T) {
ctx := context.Background()
vtParams := mysql.ConnParams{
Host: "localhost",
Port: clusterInstance.VtgateMySQLPort,
}
conn, err := mysql.Connect(ctx, &vtParams)
require.NoError(t, err)
defer conn.Close()
Expand Down Expand Up @@ -424,10 +416,6 @@ func TestNumericPrecisionScale(t *testing.T) {
}

func TestDeleteAlias(t *testing.T) {
vtParams := mysql.ConnParams{
Host: "localhost",
Port: clusterInstance.VtgateMySQLPort,
}
conn, err := mysql.Connect(context.Background(), &vtParams)
require.NoError(t, err)
defer conn.Close()
Expand All @@ -437,10 +425,6 @@ func TestDeleteAlias(t *testing.T) {
}

func TestFloatValueDefault(t *testing.T) {
vtParams := mysql.ConnParams{
Host: "localhost",
Port: clusterInstance.VtgateMySQLPort,
}
conn, err := mysql.Connect(context.Background(), &vtParams)
require.NoError(t, err)
defer conn.Close()
Expand Down
16 changes: 1 addition & 15 deletions go/test/vschemawrapper/vschema_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,21 +224,7 @@ func (vw *VSchemaWrapper) SysVarSetEnabled() bool {
}

func (vw *VSchemaWrapper) TargetDestination(qualifier string) (key.ShardDestination, *vindexes.Keyspace, topodatapb.TabletType, error) {
var keyspaceName string
if vw.Keyspace != nil {
keyspaceName = vw.Keyspace.Name
}
if vw.Dest == nil && qualifier != "" {
keyspaceName = qualifier
}
if keyspaceName == "" {
return nil, nil, 0, vterrors.VT03007()
}
keyspace := vw.V.Keyspaces[keyspaceName]
if keyspace == nil {
return nil, nil, 0, vterrors.VT05003(keyspaceName)
}
return vw.Dest, keyspace.Keyspace, vw.TabletType_, nil
return vw.Vcursor.TargetDestination(qualifier)
}

func (vw *VSchemaWrapper) TabletType() topodatapb.TabletType {
Expand Down
2 changes: 1 addition & 1 deletion go/vt/schemadiff/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func NewSchemaFromQueries(env *Environment, queries []string) (*Schema, error) {
// NewSchemaFromSQL creates a valid and normalized schema based on a SQL blob that contains
// CREATE statements for various objects (tables, views)
func NewSchemaFromSQL(env *Environment, sql string) (*Schema, error) {
statements, err := env.Parser().SplitStatements(sql)
statements, err := env.Parser().ParseMultipleIgnoreEmpty(sql)
if err != nil {
return nil, err
}
Expand Down
Loading
Loading