Skip to content

Commit df4a5d9

Browse files
committed
Enable functional index support
1 parent 360e2fe commit df4a5d9

8 files changed

Lines changed: 157 additions & 134 deletions

File tree

postgres/parser/sem/tree/format.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,9 @@ func AsStringWithFQNames(n NodeFormatter, ann *Annotations) string {
442442
return ctx.CloseAndGetString()
443443
}
444444

445-
// AsString pretty prints a node to a string.
445+
// AsString pretty prints a node to a string, with unquoted identifiers.
446446
func AsString(n NodeFormatter) string {
447-
return AsStringWithFlags(n, FmtSimple)
447+
return AsStringWithFlags(n, FmtSimple|FmtBareIdentifiers)
448448
}
449449

450450
// ErrString pretty prints a node to a string. Identifiers are not quoted.

server/analyzer/validate_create_table.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ func schToColMap(sch sql.Schema) map[string]*sql.Column {
124124
func validateIndex(ctx *sql.Context, colMap map[string]*sql.Column, idxDef *sql.IndexDef) error {
125125
seenCols := make(map[string]struct{})
126126
for _, idxCol := range idxDef.Columns {
127+
if idxCol.Expression != nil {
128+
continue
129+
}
130+
127131
schCol, exists := colMap[strings.ToLower(idxCol.Name)]
128132
if !exists {
129133
return sql.ErrKeyColumnDoesNotExist.New(idxCol.Name)

server/ast/index_elem.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ import (
2727
func nodeIndexElemList(ctx *Context, node tree.IndexElemList) ([]*vitess.IndexField, error) {
2828
vitessIndexColumns := make([]*vitess.IndexField, 0, len(node))
2929
for _, inputColumn := range node {
30-
if inputColumn.Expr != nil {
31-
return nil, errors.Errorf("expression index attribute is not yet supported")
32-
}
33-
3430
if inputColumn.Collation != "" {
3531
logrus.Warn("index attribute collation is not yet supported, ignoring")
3632
}

server/tables/information_schema/columns_table.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ func getRowsFromTable(ctx *sql.Context, db information_schema.DbWithNames, t sql
204204

205205
tblName := t.Name()
206206
for i, col := range information_schema.SchemaForTable(t, db.Database, allColsWithDefaultValue) {
207+
if col.HiddenSystem {
208+
continue
209+
}
207210
r := getRowFromColumn(ctx, i, col, db.CatalogName, db.SchemaName, tblName)
208211
if r != nil {
209212
rows = append(rows, r)

testing/generation/command_docs/output/create_index_test.go

Lines changed: 121 additions & 121 deletions
Large diffs are not rendered by default.

testing/go/enginetest/doltgres_engine_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,12 @@ func TestIndexes(t *testing.T) {
792792
enginetest.TestIndexes(t, harness)
793793
}
794794

795+
func TestIndexedExpressions(t *testing.T) {
796+
harness := newDoltgresServerHarness(t)
797+
defer harness.Close()
798+
enginetest.TestIndexedExpressions(t, harness)
799+
}
800+
795801
func TestIndexPrefix(t *testing.T) {
796802
t.Skip()
797803
harness := newDoltgresServerHarness(t)

testing/go/enginetest/doltgres_harness_test.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,23 @@ var defaultSkippedQueries = []string{
113113
"show create table fk_tbl", // we create an extra key for the FK that vanilla gms does not
114114
"show indexes from", // we create / expose extra indexes (for foreign keys)
115115
"show global variables like", // we set extra variables
116+
"show columns from", // MySQL SHOW variant with no PostgreSQL equivalent
117+
"show extended columns from", // MySQL SHOW variant with no PostgreSQL equivalent
118+
116119
// unsupported doltgres syntax
117120
// " WITH ",
118121
// " OVER ",
119122
// string functions are broken due to incompatible types
120123
"HEX(",
121124
"TO_BASE64(",
125+
// MySQL-specific functions not supported in doltgresql
126+
"json_unquote", // MySQL JSON function
127+
"year(", // YEAR() functional index hits a type-incompatibility in doltgresql
128+
129+
// MySQL-specific operators and syntax not supported in PostgreSQL
130+
"<=>", // null-safe equality (PostgreSQL uses IS NOT DISTINCT FROM)
131+
"modify column", // MySQL ALTER TABLE MODIFY COLUMN syntax
132+
"column first", // MySQL ADD COLUMN ... FIRST positioning
122133
}
123134

124135
// Setup sets the setup scripts for this DoltHarness's engine
@@ -729,6 +740,10 @@ func getDmlResult(rows pgx.Rows, query string) (sql.Row, bool) {
729740
return sql.NewRow(gmstypes.NewOkResult(0)), true
730741
case strings.HasPrefix(tag.String(), "ALTER TABLE"):
731742
return sql.NewRow(gmstypes.NewOkResult(0)), true
743+
case strings.HasPrefix(tag.String(), "CREATE INDEX"):
744+
return sql.NewRow(gmstypes.NewOkResult(0)), true
745+
case strings.HasPrefix(tag.String(), "DROP INDEX"):
746+
return sql.NewRow(gmstypes.NewOkResult(0)), true
732747
case strings.HasPrefix(tag.String(), "TRUNCATE"):
733748
return sql.NewRow(gmstypes.NewOkResult(0)), true
734749
case strings.HasPrefix(tag.String(), "SET"):
@@ -814,12 +829,15 @@ func unwrapResultColumn(v any) (any, error) {
814829
}
815830
}
816831

832+
// IsServerBacked implements enginetest.ServerBackedEngine, marking DoltgresQueryEngine
833+
// as a server-backed engine so that plan-inspection checks (evalIndexTest, etc.) are
834+
// skipped, matching the behavior of GMS's own ServerQueryEngine.
835+
func (d *DoltgresQueryEngine) IsServerBacked() bool { return true }
836+
817837
func (d *DoltgresQueryEngine) EngineAnalyzer() *analyzer.Analyzer {
818838
// TODO: this is a shim to get simple tests to work, we need to restructure the tests to not require access to
819839
// an analyzer
820-
catalog := &analyzer.Catalog{}
821-
catalog.AuthHandler = sql.GetAuthorizationHandlerFactory().CreateHandler(catalog)
822-
840+
catalog := analyzer.NewCatalog(nil, sql.EngineOverrides{})
823841
return &analyzer.Analyzer{
824842
Catalog: catalog,
825843
}

testing/go/index_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,10 +1076,6 @@ func TestBasicIndexing(t *testing.T) {
10761076
// ignored warning-generating unsupported options
10771077
Query: "CREATE INDEX v1_idx ON test(v1 varchar_pattern_ops) WITH (storage_opt1 = foo) TABLESPACE tablespace_name;",
10781078
},
1079-
{
1080-
Query: "CREATE INDEX v1_idx2 ON test( (concat(v1, v1)) ) ;",
1081-
ExpectedErr: "not yet supported",
1082-
},
10831079
{
10841080
Query: "CREATE INDEX v1_idx2 ON test using hash (v1);",
10851081
ExpectedErr: "not yet supported",

0 commit comments

Comments
 (0)