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
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ require (
github.com/dolthub/dolt/go v0.40.5-0.20260901102237-645f6accd917
github.com/dolthub/eventsapi_schema v0.0.0-20260715220557-d9b4a1c6b4d4
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
github.com/dolthub/go-mysql-server v0.20.1-0.20260901192735-5d6be3976cd5
github.com/dolthub/go-mysql-server v0.20.1-0.20260901200741-de2dfefb8dec
github.com/dolthub/pg_query_go/v6 v6.0.0-20251215122834-fb20be4254d1
github.com/dolthub/sqllogictest/go v0.0.0-20260624223518-788480b24166
github.com/dolthub/vitess v0.0.0-20260828193927-f9eb707fd659
github.com/dolthub/vitess v0.0.0-20260831192502-e34df639d960
github.com/fatih/color v1.13.0
github.com/go-sql-driver/mysql v1.9.3
github.com/goccy/go-json v0.10.2
Expand Down Expand Up @@ -142,6 +142,7 @@ require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d // indirect
github.com/kch42/buzhash v0.0.0-20160816060738-9bdec3dec7c6 // indirect
github.com/klauspost/compress v1.18.0 // indirect
Expand Down
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ github.com/dolthub/fslock v0.0.5 h1:QoXhBhgY1oumHE26qyE7tgmXUT8qjJwxsIzo54O/B/k=
github.com/dolthub/fslock v0.0.5/go.mod h1:sdofYYqE0D79zNZyB4/kmlnsQOVap1C2yByjGKSirEM=
github.com/dolthub/go-icu-regex v0.0.0-20260610153742-72563bc7ca83 h1:FEMjCGEroDnY/BXyAffVZxUpXhP2GpoUJyyq5KaLn8c=
github.com/dolthub/go-icu-regex v0.0.0-20260610153742-72563bc7ca83/go.mod h1:F3cnm+vMRK1HaU6+rNqQrOCyR03HHhR1GWG2gnPOqaE=
github.com/dolthub/go-mysql-server v0.20.1-0.20260901192735-5d6be3976cd5 h1:OjIEbos9AZW660TkKANOzDjMnOZgFchyJkhcXXulCcE=
github.com/dolthub/go-mysql-server v0.20.1-0.20260901192735-5d6be3976cd5/go.mod h1:CtDdfkAma4klv+UQbEmV4AkVvkSyXf/V3iRpIDu6c2I=
github.com/dolthub/go-mysql-server v0.20.1-0.20260901200741-de2dfefb8dec h1:kwUmkRRUt7HD9umb/+mM5OTCnA9LYznwJBqyMpF6dMM=
github.com/dolthub/go-mysql-server v0.20.1-0.20260901200741-de2dfefb8dec/go.mod h1:W1u45n8fFmy/C4dYXoQ2jQPzbKTA8WX2kNjLkusig2I=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
github.com/dolthub/ishell v0.0.0-20260414231531-5f031e3e9037 h1:oIW9HwuWrhxv+4HZxA+QQSKHLqWFyXZ2FmNjUYwkdiM=
Expand All @@ -268,8 +268,8 @@ github.com/dolthub/pg_query_go/v6 v6.0.0-20251215122834-fb20be4254d1 h1:GY17cGA4
github.com/dolthub/pg_query_go/v6 v6.0.0-20251215122834-fb20be4254d1/go.mod h1:qnrZP3/1slFl2Bq5yw38HLOsArZareGwdpEceriblLc=
github.com/dolthub/sqllogictest/go v0.0.0-20260624223518-788480b24166 h1:fdexJBpLDyAGnFbviZYfZ0jhLMnbTWTh39CyQ1EhA28=
github.com/dolthub/sqllogictest/go v0.0.0-20260624223518-788480b24166/go.mod h1:e/FIZVvT2IR53HBCAo41NjqgtEnjMJGKca3Y/dAmZaA=
github.com/dolthub/vitess v0.0.0-20260828193927-f9eb707fd659 h1:DJfoBlihBdLY6KokA+wCXoYYeOgwrKuiZFPHJP8koi8=
github.com/dolthub/vitess v0.0.0-20260828193927-f9eb707fd659/go.mod h1:5SVEJgAhw5nnQUFnGgKI1Svqes1Mw+zKUsalyxmOuG0=
github.com/dolthub/vitess v0.0.0-20260831192502-e34df639d960 h1:NMg7ETQiEHsSfH8ckCTI7q0ukycwOF4qEuJ/jO1QUIM=
github.com/dolthub/vitess v0.0.0-20260831192502-e34df639d960/go.mod h1:5SVEJgAhw5nnQUFnGgKI1Svqes1Mw+zKUsalyxmOuG0=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
Expand Down Expand Up @@ -520,7 +520,6 @@ github.com/jackc/pgx/v5 v5.9.2/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM
github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.3.0 h1:eHK/5clGOatcjX3oWGBO/MpxpbHzSwud5EWTSCI+MX0=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jcmturner/gofork v0.0.0-20180107083740-2aebee971930/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o=
Expand Down
27 changes: 11 additions & 16 deletions server/ast/drop_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,17 @@
package ast

import (
"github.com/cockroachdb/errors"

vitess "github.com/dolthub/vitess/go/vt/sqlparser"

"github.com/dolthub/doltgresql/postgres/parser/sem/tree"
"github.com/dolthub/doltgresql/server/auth"
)

// nodeDropTable handles *tree.DropTable nodes.
func nodeDropTable(ctx *Context, node *tree.DropTable) (*vitess.DDL, error) {
func nodeDropTable(ctx *Context, node *tree.DropTable) (vitess.Statement, error) {
if node == nil || len(node.Names) == 0 {
return nil, nil
}
switch node.DropBehavior {
case tree.DropDefault:
// Default behavior, nothing to do
case tree.DropRestrict:
return nil, errors.Errorf("RESTRICT is not yet supported")
case tree.DropCascade:
return nil, errors.Errorf("CASCADE is not yet supported")
}
tableNames := make([]vitess.TableName, len(node.Names))
authTableNames := make([]string, 0, len(node.Names)*3)
for i := range node.Names {
Expand All @@ -47,14 +37,19 @@ func nodeDropTable(ctx *Context, node *tree.DropTable) (*vitess.DDL, error) {
authTableNames = append(authTableNames,
tableNames[i].DbQualifier.String(), tableNames[i].SchemaQualifier.String(), tableNames[i].Name.String())
}
authInformation := vitess.AuthInformation{
AuthType: auth.AuthType_DROPTABLE,
TargetType: auth.AuthTargetType_TableIdentifiers,
TargetNames: authTableNames,
}
return &vitess.DDL{
Comment thread
zachmu marked this conversation as resolved.
Comment thread
zachmu marked this conversation as resolved.
Comment thread
zachmu marked this conversation as resolved.
Action: vitess.DropStr,
FromTables: tableNames,
IfExists: node.IfExists,
Auth: vitess.AuthInformation{
AuthType: auth.AuthType_DROPTABLE,
TargetType: auth.AuthTargetType_TableIdentifiers,
TargetNames: authTableNames,
},
// RESTRICT is the default behavior in Postgres, so both are handled by the standard DROP TABLE path, which
// refuses to drop a table that other objects depend on. CASCADE also drops the dependent objects, which the
// DROP TABLE pre-execution hook handles.
Cascade: node.DropBehavior == tree.DropCascade,
Auth: authInformation,
}, nil
}
11 changes: 9 additions & 2 deletions server/hook/delete_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

// BeforeTableDeletion performs all validation necessary to ensure that table deletion does not leave the database in an
// invalid state.
func BeforeTableDeletion(ctx *sql.Context, _ sql.StatementRunner, nodeInterface sql.Node) (sql.Node, error) {
func BeforeTableDeletion(ctx *sql.Context, runner sql.StatementRunner, nodeInterface sql.Node) (sql.Node, error) {
// TODO: handle casts using a table name
n, ok := nodeInterface.(*plan.DropTable)
if !ok {
Expand All @@ -47,7 +47,14 @@ func BeforeTableDeletion(ctx *sql.Context, _ sql.StatementRunner, nodeInterface
resolvedTables = append(resolvedTables, doltTable)
allTableNames = append(allTableNames, doltTable.TableName())
}
// TODO: handle DROP TABLE CASCADE
if n.Cascade {
Comment thread
zachmu marked this conversation as resolved.
// CASCADE drops the objects that depend on the dropped tables before the standard drop path runs.
if err := cascadeDropDependencies(ctx, runner, allTableNames); err != nil {
return nil, err
}
}
// These checks error on any remaining dependency: everything with CASCADE was dropped above, so anything left
// (or anything at all, without CASCADE) blocks the drop.
for _, doltTable := range resolvedTables {
// Check if the table is in a column
if err := beforeTableDeletionCheckTableColumns(ctx, doltTable, allTableNames); err != nil {
Expand Down
Loading
Loading