File tree Expand file tree Collapse file tree 7 files changed +48
-6
lines changed Expand file tree Collapse file tree 7 files changed +48
-6
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,15 @@ func (idx *Index) Expressions() []string {
7373 return exprs
7474}
7575
76+ func (idx * Index ) UnqualifiedExpressions () []string {
77+ exprs := make ([]string , len (idx .Exprs ))
78+ for i , e := range idx .Exprs {
79+ str := e .String ()
80+ exprs [i ] = str [strings .IndexByte (str , '.' )+ 1 :]
81+ }
82+ return exprs
83+ }
84+
7685func (idx * Index ) ExtendedExpressions () []string {
7786 var exprs []string
7887 foundCols := make (map [string ]struct {})
Original file line number Diff line number Diff line change 1515package analyzer
1616
1717import (
18+ "strings"
1819 "testing"
1920
2021 "github.com/stretchr/testify/require"
@@ -142,6 +143,15 @@ func (i dummyIdx) Expressions() []string {
142143 }
143144 return exprs
144145}
146+
147+ func (i dummyIdx ) UnqualifiedExpressions () []string {
148+ exprs := make ([]string , len (i .expr ))
149+ for i , e := range i .expr {
150+ str := e .String ()
151+ exprs [i ] = str [strings .IndexByte (str , '.' )+ 1 :]
152+ }
153+ return exprs
154+ }
145155func (i * dummyIdx ) ID () string { return i .id }
146156func (i * dummyIdx ) Database () string { return i .database }
147157func (i * dummyIdx ) Table () string { return i .table }
Original file line number Diff line number Diff line change @@ -102,6 +102,8 @@ type Index interface {
102102 // one expression, it means the index has multiple columns indexed. If it's
103103 // just one, it means it may be an expression or a column.
104104 Expressions () []string
105+ // UnqualifiedExpressions returns the indexed expressions without the source.
106+ UnqualifiedExpressions () []string
105107 // IsUnique returns whether this index is unique
106108 IsUnique () bool
107109 // IsSpatial returns whether this index is a spatial index
Original file line number Diff line number Diff line change @@ -188,6 +188,14 @@ func (i testIndex) Expressions() []string {
188188 return res
189189}
190190
191+ func (i testIndex ) UnqualifiedExpressions () []string {
192+ res := make ([]string , i .numcols )
193+ for i := range res {
194+ res [i ] = fmt .Sprintf ("column_%d" , i )
195+ }
196+ return res
197+ }
198+
191199func (testIndex ) IsUnique () bool {
192200 return false
193201}
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ package sql
1616
1717import (
1818 "fmt"
19+ "strings"
1920 "testing"
2021
2122 "github.com/stretchr/testify/require"
@@ -443,6 +444,16 @@ func (i dummyIdx) Expressions() []string {
443444 }
444445 return exprs
445446}
447+
448+ func (i dummyIdx ) UnqualifiedExpressions () []string {
449+ exprs := make ([]string , len (i .expr ))
450+ for i , e := range i .expr {
451+ str := e .String ()
452+ exprs [i ] = str [strings .IndexByte (str , '.' )+ 1 :]
453+ }
454+ return exprs
455+ }
456+
446457func (i dummyIdx ) ID () string { return i .id }
447458func (i dummyIdx ) Database () string { return i .database }
448459func (i dummyIdx ) Table () string { return i .table }
Original file line number Diff line number Diff line change @@ -131,13 +131,11 @@ func newRelProps(rel RelExpr) *relProps {
131131}
132132
133133// idxExprsColumns returns the column names used in an index's expressions.
134- // TODO: this is unstable as long as periods in Index.Expressions()
135- // identifiers are ambiguous.
134+ // Identifiers are ambiguous.
136135func idxExprsColumns (idx sql.Index ) []string {
137- columns := make ([]string , len (idx .Expressions ()))
138- for i , e := range idx .Expressions () {
139- parts := strings .Split (e , "." )
140- columns [i ] = strings .ToLower (parts [1 ])
136+ columns := idx .UnqualifiedExpressions ()
137+ for i := 0 ; i < len (columns ); i ++ {
138+ columns [i ] = strings .ToLower (columns [i ])
141139 }
142140 return columns
143141}
Original file line number Diff line number Diff line change @@ -217,6 +217,10 @@ func (i dummyIndex) Expressions() []string {
217217 return i .cols
218218}
219219
220+ func (i dummyIndex ) UnqualifiedExpressions () []string {
221+ return i .cols
222+ }
223+
220224func (dummyIndex ) IsUnique () bool {
221225 return true
222226}
You can’t perform that action at this time.
0 commit comments