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 {
73
73
return exprs
74
74
}
75
75
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
+
76
85
func (idx * Index ) ExtendedExpressions () []string {
77
86
var exprs []string
78
87
foundCols := make (map [string ]struct {})
Original file line number Diff line number Diff line change 15
15
package analyzer
16
16
17
17
import (
18
+ "strings"
18
19
"testing"
19
20
20
21
"github.com/stretchr/testify/require"
@@ -142,6 +143,15 @@ func (i dummyIdx) Expressions() []string {
142
143
}
143
144
return exprs
144
145
}
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
+ }
145
155
func (i * dummyIdx ) ID () string { return i .id }
146
156
func (i * dummyIdx ) Database () string { return i .database }
147
157
func (i * dummyIdx ) Table () string { return i .table }
Original file line number Diff line number Diff line change @@ -102,6 +102,8 @@ type Index interface {
102
102
// one expression, it means the index has multiple columns indexed. If it's
103
103
// just one, it means it may be an expression or a column.
104
104
Expressions () []string
105
+ // UnqualifiedExpressions returns the indexed expressions without the source.
106
+ UnqualifiedExpressions () []string
105
107
// IsUnique returns whether this index is unique
106
108
IsUnique () bool
107
109
// 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 {
188
188
return res
189
189
}
190
190
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
+
191
199
func (testIndex ) IsUnique () bool {
192
200
return false
193
201
}
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ package sql
16
16
17
17
import (
18
18
"fmt"
19
+ "strings"
19
20
"testing"
20
21
21
22
"github.com/stretchr/testify/require"
@@ -443,6 +444,16 @@ func (i dummyIdx) Expressions() []string {
443
444
}
444
445
return exprs
445
446
}
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
+
446
457
func (i dummyIdx ) ID () string { return i .id }
447
458
func (i dummyIdx ) Database () string { return i .database }
448
459
func (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 {
131
131
}
132
132
133
133
// 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.
136
135
func 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 ])
141
139
}
142
140
return columns
143
141
}
Original file line number Diff line number Diff line change @@ -217,6 +217,10 @@ func (i dummyIndex) Expressions() []string {
217
217
return i .cols
218
218
}
219
219
220
+ func (i dummyIndex ) UnqualifiedExpressions () []string {
221
+ return i .cols
222
+ }
223
+
220
224
func (dummyIndex ) IsUnique () bool {
221
225
return true
222
226
}
You can’t perform that action at this time.
0 commit comments