Skip to content

Commit 3610b86

Browse files
authored
Merge pull request #2695 from dolthub/elianddb-1b8bc4a1
[auto-bump] [no-release-notes] dependency by elianddb
2 parents 51d5912 + 22c15a5 commit 3610b86

9 files changed

Lines changed: 88 additions & 26 deletions

File tree

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ require (
66
github.com/PuerkitoBio/goquery v1.8.1
77
github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a
88
github.com/cockroachdb/errors v1.7.5
9-
github.com/dolthub/dolt/go v0.40.5-0.20260430172110-36fcc634f302
9+
github.com/dolthub/dolt/go v0.40.5-0.20260505174628-1b8bc4a1f0fd
1010
github.com/dolthub/eventsapi_schema v0.0.0-20260310172945-37a9265ade69
1111
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
12-
github.com/dolthub/go-mysql-server v0.20.1-0.20260427172105-a0b357da2f1d
12+
github.com/dolthub/go-mysql-server v0.20.1-0.20260504234906-b4fc3a6e3cc5
1313
github.com/dolthub/pg_query_go/v6 v6.0.0-20251215122834-fb20be4254d1
1414
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216
15-
github.com/dolthub/vitess v0.0.0-20260424215137-ec6bd432b0be
15+
github.com/dolthub/vitess v0.0.0-20260504232330-bcb1b9015c48
1616
github.com/fatih/color v1.13.0
1717
github.com/goccy/go-json v0.10.2
1818
github.com/gogo/protobuf v1.3.2

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ github.com/dolthub/aws-sdk-go-ini-parser v0.0.0-20250305001723-2821c37f6c12 h1:I
245245
github.com/dolthub/aws-sdk-go-ini-parser v0.0.0-20250305001723-2821c37f6c12/go.mod h1:rN7X8BHwkjPcfMQQ2QTAq/xM3leUSGLfb+1Js7Y6TVo=
246246
github.com/dolthub/dolt-mcp v0.3.4 h1:AyG5cw+fNWXDHXujtQnqUPZrpWtPg6FN6yYtjv1pP44=
247247
github.com/dolthub/dolt-mcp v0.3.4/go.mod h1:bCZ7KHvDYs+M0e+ySgmGiNvLhcwsN7bbf5YCyillLrk=
248-
github.com/dolthub/dolt/go v0.40.5-0.20260430172110-36fcc634f302 h1:rsAzhociWfQbOyPGaoPOh6gHLEG3dXO9NM6kHVp6Zcc=
249-
github.com/dolthub/dolt/go v0.40.5-0.20260430172110-36fcc634f302/go.mod h1:+OAy6JNtk6d+T6WbDqSOvhwjapYmmmH0cKHI0VGygwY=
248+
github.com/dolthub/dolt/go v0.40.5-0.20260505174628-1b8bc4a1f0fd h1:nWpxjJMGeNNrKnMzqcihLdsOcdzHPZXw1VfwKrh1eHU=
249+
github.com/dolthub/dolt/go v0.40.5-0.20260505174628-1b8bc4a1f0fd/go.mod h1:bjYYYVBPSlOKvpsX5AdGftveZQCIC5cyqvFUK5I+0CQ=
250250
github.com/dolthub/eventsapi_schema v0.0.0-20260310172945-37a9265ade69 h1:JShhbqMw26nKx3pqqu/cFxOpzBkN+4elVhzuUfgDw2k=
251251
github.com/dolthub/eventsapi_schema v0.0.0-20260310172945-37a9265ade69/go.mod h1:SSLraQS/jGLYFgff3vuZ+JbVUct6vyEeMzjLBqWqoyM=
252252
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 h1:u3PMzfF8RkKd3lB9pZ2bfn0qEG+1Gms9599cr0REMww=
@@ -255,8 +255,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U=
255255
github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0=
256256
github.com/dolthub/go-icu-regex v0.0.0-20260412212219-49724d547866 h1:U6gSf5I0e6h6GP1/5Sa7D2lWW1CWfcVPtY5wkyHq6jY=
257257
github.com/dolthub/go-icu-regex v0.0.0-20260412212219-49724d547866/go.mod h1:F3cnm+vMRK1HaU6+rNqQrOCyR03HHhR1GWG2gnPOqaE=
258-
github.com/dolthub/go-mysql-server v0.20.1-0.20260427172105-a0b357da2f1d h1:0ptkeudblr8Ee6fmah6T/1nmnqAC5XXUmHiknZiGL58=
259-
github.com/dolthub/go-mysql-server v0.20.1-0.20260427172105-a0b357da2f1d/go.mod h1:O43PPQxMeNi7O5idizj6Itf2TZcSYfI/0WU24xhXg4I=
258+
github.com/dolthub/go-mysql-server v0.20.1-0.20260504234906-b4fc3a6e3cc5 h1:F7prHhrdLPuzacr9+hpklMxZ4Q2M2dqsKzxX8FqiRXs=
259+
github.com/dolthub/go-mysql-server v0.20.1-0.20260504234906-b4fc3a6e3cc5/go.mod h1:hhGHXWslZ2AFzPkgJqoHtH6fZ/lNMk25SAe2RHKpQLU=
260260
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
261261
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
262262
github.com/dolthub/ishell v0.0.0-20260414231531-5f031e3e9037 h1:oIW9HwuWrhxv+4HZxA+QQSKHLqWFyXZ2FmNjUYwkdiM=
@@ -267,8 +267,8 @@ github.com/dolthub/pg_query_go/v6 v6.0.0-20251215122834-fb20be4254d1 h1:GY17cGA4
267267
github.com/dolthub/pg_query_go/v6 v6.0.0-20251215122834-fb20be4254d1/go.mod h1:qnrZP3/1slFl2Bq5yw38HLOsArZareGwdpEceriblLc=
268268
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216 h1:JWkKRE4EHUcEVQCMRBej8DYxjYjRz/9MdF/NNQh0o70=
269269
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216/go.mod h1:e/FIZVvT2IR53HBCAo41NjqgtEnjMJGKca3Y/dAmZaA=
270-
github.com/dolthub/vitess v0.0.0-20260424215137-ec6bd432b0be h1:m01DFtn4xQhLWni8bCbRRjcjeiOZkAgaj2fOWGpPr6A=
271-
github.com/dolthub/vitess v0.0.0-20260424215137-ec6bd432b0be/go.mod h1:dKAkzdfRkAudpc0g8JOQ0eiEjV83TYIFz/yNIEdcjXM=
270+
github.com/dolthub/vitess v0.0.0-20260504232330-bcb1b9015c48 h1:znkwaIJnYUf9kL6hNctwWOaKDH0h1jWevwdmo0Otojo=
271+
github.com/dolthub/vitess v0.0.0-20260504232330-bcb1b9015c48/go.mod h1:dKAkzdfRkAudpc0g8JOQ0eiEjV83TYIFz/yNIEdcjXM=
272272
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
273273
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
274274
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=

server/ast/alter_table.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,10 @@ func nodeAlterTableAddColumn(ctx *Context, node *tree.AlterTableAddColumn, table
245245
if err != nil {
246246
return nil, err
247247
}
248-
tableSpec.AddConstraint(&vitess.ConstraintDefinition{Details: constraintDef})
248+
tableSpec.AddConstraint(&vitess.ConstraintDefinition{
249+
Name: string(node.ColumnDef.References.ConstraintName),
250+
Details: constraintDef,
251+
})
249252
}
250253

251254
return &vitess.DDL{

server/ast/column_table_def.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,12 @@ func nodeColumnTableDef(ctx *Context, node *tree.ColumnTableDef) (*vitess.Column
7878
defaultExpr = &vitess.ParenExpr{Expr: defaultExpr}
7979
}
8080

81-
var fkDef *vitess.ForeignKeyDefinition
8281
if node.References.Table != nil {
8382
if len(node.References.Col) == 0 {
8483
return nil, errors.Errorf("implicit primary key matching on column foreign key is not yet supported")
8584
}
86-
fkDef, err = nodeForeignKeyConstraintTableDef(ctx, &tree.ForeignKeyConstraintTableDef{
87-
Name: node.References.ConstraintName,
88-
Table: *node.References.Table,
89-
FromCols: tree.NameList{node.Name},
90-
ToCols: tree.NameList{node.References.Col},
91-
Actions: node.References.Actions,
92-
Match: node.References.Match,
93-
})
94-
if err != nil {
95-
return nil, err
96-
}
85+
// Callers register the foreign key via the table constraint list, so ForeignKeyDef
86+
// is left unset here to avoid creating the same constraint twice.
9787
}
9888

9989
if len(node.Computed.Options) > 0 {
@@ -164,7 +154,6 @@ func nodeColumnTableDef(ctx *Context, node *tree.ColumnTableDef) (*vitess.Column
164154
Length: convertType.Length,
165155
Scale: convertType.Scale,
166156
KeyOpt: keyOpt,
167-
ForeignKeyDef: fkDef,
168157
GeneratedExpr: generated,
169158
Stored: generated != nil, // postgres generated columns are always stored, never virtual
170159
},

server/ast/table_def.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func assignTableDef(ctx *Context, node tree.TableDef, target *vitess.DDL) error
6161
return err
6262
}
6363
target.TableSpec.Constraints = append(target.TableSpec.Constraints, &vitess.ConstraintDefinition{
64+
Name: string(node.References.ConstraintName),
6465
Details: fkDef,
6566
})
6667
}

server/tables/dtables/ignore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func convertTupleToIgnoreBoolean(ctx context.Context, valueDesc *val.TupleDesc,
6060

6161
// getIgnoreTablePatternKey reads the pattern key from a tuple and returns it.
6262
func getIgnoreTablePatternKey(ctx context.Context, keyDesc *val.TupleDesc, keyTuple val.Tuple) (string, error) {
63-
key, ok, err := keyDesc.GetStringAdaptiveValue(0, nil, keyTuple)
63+
key, ok, err := keyDesc.GetStringAdaptiveValue(ctx, 0, nil, keyTuple)
6464
if err != nil {
6565
return "", err
6666
}

server/types/type.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,12 @@ func (t *DoltgresType) Compare(ctx context.Context, v1 interface{}, v2 interface
217217

218218
if t.TypType == TypeType_Enum {
219219
// TODO: temporary solution to getting the enum type (which has label info) into the 'enum_cmp' function
220-
qf := globalFunctionRegistry.GetFunction(ctx.(*sql.Context), t.CompareFunc)
220+
// ctx is not guaranteed to be a *sql.Context when called from index comparator goroutines.
221+
sqlCtx, ok := ctx.(*sql.Context)
222+
if !ok {
223+
sqlCtx = sql.NewEmptyContext()
224+
}
225+
qf := globalFunctionRegistry.GetFunction(sqlCtx, t.CompareFunc)
221226
resTypes := qf.ResolvedTypes()
222227
newFunc := qf.WithResolvedTypes([]*DoltgresType{t, t, resTypes[len(resTypes)-1]})
223228
i, err := newFunc.(QuickFunction).CallVariadic(nil, v1, v2)
@@ -226,7 +231,12 @@ func (t *DoltgresType) Compare(ctx context.Context, v1 interface{}, v2 interface
226231
}
227232
return int(i.(int32)), nil
228233
} else if t == Oidvector {
229-
i, err := globalFunctionRegistry.GetFunction(ctx.(*sql.Context), t.CompareFunc).CallVariadic(nil, v1, v2)
234+
// ctx is not guaranteed to be a *sql.Context when called from index comparator goroutines.
235+
sqlCtx, ok := ctx.(*sql.Context)
236+
if !ok {
237+
sqlCtx = sql.NewEmptyContext()
238+
}
239+
i, err := globalFunctionRegistry.GetFunction(sqlCtx, t.CompareFunc).CallVariadic(nil, v1, v2)
230240
if err != nil {
231241
return 0, err
232242
}

testing/go/foreign_keys_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,44 @@ func TestForeignKeys(t *testing.T) {
8888
},
8989
},
9090
},
91+
{
92+
// See https://www.postgresql.org/docs/current/ddl-constraints.html#DDL-CONSTRAINTS-FK
93+
Name: "inline column REFERENCES enforces a foreign key constraint",
94+
SetUpScript: []string{
95+
`CREATE TABLE parent (a INT PRIMARY KEY)`,
96+
`CREATE TABLE child (id INT PRIMARY KEY, pid INT REFERENCES parent(a))`,
97+
`INSERT INTO parent VALUES (1)`,
98+
},
99+
Assertions: []ScriptTestAssertion{
100+
{
101+
Query: "INSERT INTO child VALUES (1, 1)",
102+
},
103+
{
104+
Query: "INSERT INTO child VALUES (2, 999)",
105+
ExpectedErr: "Foreign key violation",
106+
},
107+
},
108+
},
109+
{
110+
// See https://github.com/morenoh149/postgresDBSamples/blob/master/french-towns-communes-francaises/french-towns-communes-francaises.sql
111+
Name: "inline column REFERENCES enforces constraints across a chain of related tables",
112+
SetUpScript: []string{
113+
`CREATE TABLE regions (id SERIAL UNIQUE NOT NULL, code VARCHAR(4) UNIQUE NOT NULL, name TEXT UNIQUE NOT NULL)`,
114+
`CREATE TABLE departments (id SERIAL UNIQUE NOT NULL, code VARCHAR(4) UNIQUE NOT NULL, region VARCHAR(4) NOT NULL REFERENCES regions(code), name TEXT UNIQUE NOT NULL)`,
115+
`CREATE TABLE towns (id SERIAL UNIQUE NOT NULL, code VARCHAR(10) NOT NULL, name TEXT NOT NULL, department VARCHAR(4) NOT NULL REFERENCES departments(code), UNIQUE (code, department))`,
116+
`INSERT INTO regions VALUES (1, '01', 'Region1')`,
117+
`INSERT INTO departments VALUES (1, 'D01', '01', 'Department1')`,
118+
},
119+
Assertions: []ScriptTestAssertion{
120+
{
121+
Query: "INSERT INTO towns VALUES (1, 'T01', 'Town1', 'D01')",
122+
},
123+
{
124+
Query: "INSERT INTO towns VALUES (2, 'T02', 'Town2', 'NOPE')",
125+
ExpectedErr: "Foreign key violation",
126+
},
127+
},
128+
},
91129
{
92130
Name: "text foreign key",
93131
SetUpScript: []string{

testing/go/types_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3825,6 +3825,27 @@ var enumTypeTests = []ScriptTest{
38253825
},
38263826
},
38273827
},
3828+
{
3829+
Name: "btree index scan on enum column returns correct rows",
3830+
SetUpScript: []string{
3831+
`CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple')`,
3832+
`CREATE TABLE enumtest (col rainbow)`,
3833+
`INSERT INTO enumtest VALUES ('red'), ('orange'), ('yellow'), ('green')`,
3834+
`CREATE UNIQUE INDEX enumtest_btree ON enumtest USING btree (col)`,
3835+
// Force the planner to use the btree index rather than a sequential scan.
3836+
`SET enable_seqscan = off`,
3837+
`SET enable_bitmapscan = off`,
3838+
},
3839+
Assertions: []ScriptTestAssertion{
3840+
{Query: `SELECT * FROM enumtest WHERE col = 'orange'`, Expected: []sql.Row{{"orange"}}},
3841+
{
3842+
Query: `SELECT * FROM enumtest WHERE col > 'orange' ORDER BY col`,
3843+
// Enum values sort by their position in the type definition, not alphabetically.
3844+
Expected: []sql.Row{{"yellow"}, {"green"}},
3845+
},
3846+
{Query: `SELECT * FROM enumtest WHERE col < 'orange' ORDER BY col`, Expected: []sql.Row{{"red"}}},
3847+
},
3848+
},
38283849
{
38293850
Skip: true,
38303851
Name: "create type with existing array type name updates the name of the array type",

0 commit comments

Comments
 (0)