Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete fixidx package #2003

Merged
merged 2 commits into from
Sep 20, 2023
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
13 changes: 10 additions & 3 deletions sql/analyzer/apply_indexes_from_outer_scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"fmt"
"strings"

"github.com/dolthub/go-mysql-server/sql/fixidx"

"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/expression"
"github.com/dolthub/go-mysql-server/sql/plan"
Expand Down Expand Up @@ -282,7 +280,7 @@ func getSubqueryIndexes(
func tablesInScope(scope *plan.Scope) []string {
tables := make(map[string]bool)
for _, node := range scope.InnerToOuter() {
for _, col := range fixidx.Schemas(node.Children()) {
for _, col := range Schemas(node.Children()) {
tables[col.Source] = true
}
}
Expand All @@ -292,3 +290,12 @@ func tablesInScope(scope *plan.Scope) []string {
}
return tableSlice
}

// Schemas returns the Schemas for the nodes given appended in to a single one
func Schemas(nodes []sql.Node) sql.Schema {
var schema sql.Schema
for _, n := range nodes {
schema = append(schema, n.Schema()...)
}
return schema
}
12 changes: 10 additions & 2 deletions sql/analyzer/inserts.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package analyzer

import (
"fmt"
"strings"

"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/expression"
"github.com/dolthub/go-mysql-server/sql/fixidx"
"github.com/dolthub/go-mysql-server/sql/plan"
"github.com/dolthub/go-mysql-server/sql/transform"
"github.com/dolthub/go-mysql-server/sql/types"
Expand Down Expand Up @@ -149,10 +149,18 @@ func wrapRowSource(ctx *sql.Context, scope *plan.Scope, logFn func(string, ...an
}
var err error

colIdx := make(map[string]int)
for i, c := range schema {
colIdx[fmt.Sprintf("%s.%s", strings.ToLower(c.Source), strings.ToLower(c.Name))] = i
}
def, _, err := transform.Expr(defaultExpr, func(e sql.Expression) (sql.Expression, transform.TreeIdentity, error) {
switch e := e.(type) {
case *expression.GetField:
return fixidx.FixFieldIndexes(scope, logFn, schema, e.WithTable(destTbl.Name()))
idx, ok := colIdx[strings.ToLower(e.WithTable(destTbl.Name()).String())]
if !ok {
return nil, transform.SameTree, fmt.Errorf("field not found: %s", e.String())
}
return e.WithIndex(idx), transform.NewTree, nil
default:
return e, transform.SameTree, nil
}
Expand Down
4 changes: 4 additions & 0 deletions sql/analyzer/resolve_create_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"github.com/dolthub/go-mysql-server/sql/transform"
)

// todo this should be split into two rules. The first should be in
// planbuilder and only bind the child select, strip/merge schemas.
// a second rule should finalize analysis of the source/dest nodes
// (skipping passthrough rule).
func resolveCreateSelect(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector) (sql.Node, transform.TreeIdentity, error) {
ct, ok := n.(*plan.CreateTable)
if !ok || ct.Select() == nil {
Expand Down
6 changes: 2 additions & 4 deletions sql/analyzer/validation_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
"reflect"
"strings"

"github.com/dolthub/go-mysql-server/sql/fixidx"

"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/analyzer/analyzererrors"
"github.com/dolthub/go-mysql-server/sql/expression"
Expand Down Expand Up @@ -619,7 +617,7 @@ func validateSubqueryColumns(ctx *sql.Context, a *Analyzer, n sql.Node, scope *p
return true
}

outerScopeRowLen := len(scope.Schema()) + len(fixidx.Schemas(n.Children()))
outerScopeRowLen := len(scope.Schema()) + len(Schemas(n.Children()))
transform.Inspect(s.Query, func(n sql.Node) bool {
if n == nil {
return true
Expand All @@ -634,7 +632,7 @@ func validateSubqueryColumns(ctx *sql.Context, a *Analyzer, n sql.Node, scope *p
default:
}
if es, ok := n.(sql.Expressioner); ok {
childSchemaLen := len(fixidx.Schemas(n.Children()))
childSchemaLen := len(Schemas(n.Children()))
for _, e := range es.Expressions() {
sql.Inspect(e, func(e sql.Expression) bool {
if gf, ok := e.(*expression.GetField); ok {
Expand Down
103 changes: 0 additions & 103 deletions sql/fixidx/fix_field_indexes.go

This file was deleted.

3 changes: 3 additions & 0 deletions sql/func_deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func (k *Key) implies(other Key) bool {
// - Do a set of grouping columns constitute a strict key
// (only_full_group_by)
//
// The docs here provide a summary of how functional dependencies work:
// - /~https://github.com/cockroachdb/cockroach/blob/5a6aa768cd945118e795d1086ba6f6365f6d1284/pkg/sql/opt/props/func_dep.go#L420
//
// This object expects fields to be set in the following order:
// - notNull: what columns are non-nullable?
// - consts: what columns are constant?
Expand Down
12 changes: 9 additions & 3 deletions sql/rowexec/ddl_iters.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"bufio"
"fmt"
"io"
"log"
"strings"
"sync"
"time"
Expand All @@ -31,7 +30,6 @@ import (

"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/expression"
"github.com/dolthub/go-mysql-server/sql/fixidx"
"github.com/dolthub/go-mysql-server/sql/fulltext"
"github.com/dolthub/go-mysql-server/sql/mysql_db"
"github.com/dolthub/go-mysql-server/sql/plan"
Expand Down Expand Up @@ -197,10 +195,18 @@ func (l loadDataIter) parseFields(ctx *sql.Context, line string) ([]sql.Expressi
}
var def sql.Expression = f.Default
var err error
colIdx := make(map[string]int)
for i, c := range l.destSch {
colIdx[fmt.Sprintf("%s.%s", strings.ToLower(c.Source), strings.ToLower(c.Name))] = i
}
def, _, err = transform.Expr(f.Default, func(e sql.Expression) (sql.Expression, transform.TreeIdentity, error) {
switch e := e.(type) {
case *expression.GetField:
return fixidx.FixFieldIndexes(nil, log.Printf, l.destSch, e.WithTable(l.destSch[0].Source))
idx, ok := colIdx[strings.ToLower(e.String())]
if !ok {
return nil, transform.SameTree, fmt.Errorf("field not found: %s", e.String())
}
return e.WithIndex(idx), transform.NewTree, nil
default:
return e, transform.SameTree, nil
}
Expand Down