Skip to content

Commit b02f34c

Browse files
committed
use precedence fix
1 parent d0c7842 commit b02f34c

File tree

6 files changed

+16
-5
lines changed

6 files changed

+16
-5
lines changed

sql/analyzer/costed_index_scan.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ func indexSearchableLookup(ctx *sql.Context, n sql.Node, rt sql.TableNode, looku
114114
ret = plan.NewFilter(newFilter, ret)
115115
}
116116

117-
if fds != nil && fds.HasMax1Row() && !qFlags.JoinIsSet() && !qFlags.SubqueryIsSet() && lookup.Ranges.Len() == 1 {
118-
// Strict index lookup without a join or subquery scope will return
117+
if fds != nil && fds.HasMax1Row() && !qFlags.JoinIsSet() && !qFlags.SubqueryIsSet() && !qFlags.IsSet(sql.QFlagUnion) && lookup.Ranges.Len() == 1 {
118+
// Index lookup without join/subquery/union scope returns
119119
// at most one row. We could also use some sort of scope counting
120120
// to check for single scope.
121121
qFlags.Set(sql.QFlagMax1Row)

sql/analyzer/resolve_unions.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ func resolveUnions(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope,
4141
subqueryCtx, cancelFunc := ctx.NewSubContext()
4242
defer cancelFunc()
4343

44+
// Prevent max1Row optimization in union branches
45+
qFlags.Set(sql.QFlagUnion)
46+
4447
left, _, err := a.analyzeThroughBatch(subqueryCtx, u.Left(), scope, "default-rules", sel, qFlags)
4548
if err != nil {
4649
return nil, transform.SameTree, err
@@ -79,6 +82,9 @@ func finalizeUnions(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope
7982
subqueryCtx, cancelFunc := ctx.NewSubContext()
8083
defer cancelFunc()
8184

85+
// Prevent max1Row optimization in union branches
86+
qFlags.Set(sql.QFlagUnion)
87+
8288
scope.SetJoin(false)
8389
// TODO we could detect tree modifications here, skip rebuilding
8490
left, _, err := a.analyzeStartingAtBatch(subqueryCtx, u.Left(), scope, "default-rules", NewFinalizeUnionSel(sel), qFlags)

sql/analyzer/validate_create_table.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,8 @@ func validateAutoIncrementModify(schema sql.Schema, keyedColumns map[string]bool
792792
seen := false
793793
for _, col := range schema {
794794
if col.AutoIncrement {
795-
// Under MySQL 8.4+, AUTO_INCREMENT columns must be integer types, but not BIT types.
796-
if !types.IsInteger(col.Type) || types.IsBit(col.Type) {
795+
// AUTO_INCREMENT requires integer types
796+
if !types.IsInteger(col.Type) {
797797
return sql.ErrInvalidColumnSpecifier.New(col.Name)
798798
}
799799
// keyedColumns == nil means they are trying to add auto_increment column

sql/plan/set_op.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"strings"
2020

2121
"github.com/dolthub/go-mysql-server/sql"
22+
"github.com/dolthub/go-mysql-server/sql/types"
2223
)
2324

2425
const (
@@ -97,9 +98,12 @@ func (s *SetOp) Schema() sql.Schema {
9798
ls := s.left.Schema()
9899
rs := s.right.Schema()
99100
ret := make([]*sql.Column, len(ls))
101+
100102
for i := range ls {
101103
c := *ls[i]
102104
if i < len(rs) {
105+
// Use MySQL type precedence for UNION columns
106+
c.Type = types.GeneralizeTypes(ls[i].Type, rs[i].Type)
103107
c.Nullable = ls[i].Nullable || rs[i].Nullable
104108
}
105109
ret[i] = &c

sql/query_flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const (
4141
QFlagLimit
4242
QFlagInterval
4343
QFlagAnyAgg
44+
QFlagUnion
4445

4546
// QFlagMax1Row indicates that a query can only return at most one row
4647
QFlagMax1Row

sql/types/typecheck.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func IsUnsigned(t sql.Type) bool {
230230
if svt, ok := t.(sql.SystemVariableType); ok {
231231
t = svt.UnderlyingType()
232232
}
233-
return t == Uint8 || t == Uint16 || t == Uint24 || t == Uint32 || t == Uint64 || IsBit(t)
233+
return t == Uint8 || t == Uint16 || t == Uint24 || t == Uint32 || t == Uint64
234234
}
235235

236236
// IsYear checks if t is a year type.

0 commit comments

Comments
 (0)