@@ -266,34 +266,39 @@ func (i *Index) enginePrefix() []byte {
266266 return i .table .catalog .enginePrefix
267267}
268268
269- func (i * Index ) coversOrdCols (ordCols []* OrdCol , rangesByColID map [uint32 ]* typedValueRange ) bool {
270- if ! ordColumnsHaveSameDirection ( ordCols ) {
269+ func (i * Index ) coversOrdCols (ordExps []* OrdExp , rangesByColID map [uint32 ]* typedValueRange ) bool {
270+ if ! ordExpsHaveSameDirection ( ordExps ) {
271271 return false
272272 }
273- return i .hasPrefix (i .cols , ordCols ) || i .sortableUsing (ordCols , rangesByColID )
273+ return i .hasPrefix (i .cols , ordExps ) || i .sortableUsing (ordExps , rangesByColID )
274274}
275275
276- func ordColumnsHaveSameDirection ( cols []* OrdCol ) bool {
277- if len (cols ) == 0 {
276+ func ordExpsHaveSameDirection ( exps []* OrdExp ) bool {
277+ if len (exps ) == 0 {
278278 return true
279279 }
280280
281- desc := cols [0 ].descOrder
282- for _ , ordCol := range cols [1 :] {
283- if ordCol .descOrder != desc {
281+ desc := exps [0 ].descOrder
282+ for _ , e := range exps [1 :] {
283+ if e .descOrder != desc {
284284 return false
285285 }
286286 }
287287 return true
288288}
289289
290- func (i * Index ) hasPrefix (columns []* Column , ordCols []* OrdCol ) bool {
291- if len (ordCols ) > len (columns ) {
290+ func (i * Index ) hasPrefix (columns []* Column , ordExps []* OrdExp ) bool {
291+ if len (ordExps ) > len (columns ) {
292292 return false
293293 }
294294
295- for j , ordCol := range ordCols {
296- aggFn , _ , colName := ordCol .sel .resolve (i .table .Name ())
295+ for j , ordCol := range ordExps {
296+ sel := ordCol .AsSelector ()
297+ if sel == nil {
298+ return false
299+ }
300+
301+ aggFn , _ , colName := sel .resolve (i .table .Name ())
297302 if len (aggFn ) > 0 {
298303 return false
299304 }
@@ -306,9 +311,14 @@ func (i *Index) hasPrefix(columns []*Column, ordCols []*OrdCol) bool {
306311 return true
307312}
308313
309- func (i * Index ) sortableUsing (columns []* OrdCol , rangesByColID map [uint32 ]* typedValueRange ) bool {
314+ func (i * Index ) sortableUsing (columns []* OrdExp , rangesByColID map [uint32 ]* typedValueRange ) bool {
310315 // all columns before colID must be fixedValues otherwise the index can not be used
311- aggFn , _ , colName := columns [0 ].sel .resolve (i .table .Name ())
316+ sel := columns [0 ].AsSelector ()
317+ if sel == nil {
318+ return false
319+ }
320+
321+ aggFn , _ , colName := sel .resolve (i .table .Name ())
312322 if len (aggFn ) > 0 {
313323 return false
314324 }
@@ -327,7 +337,6 @@ func (i *Index) sortableUsing(columns []*OrdCol, rangesByColID map[uint32]*typed
327337 if ok && colRange .unitary () {
328338 continue
329339 }
330-
331340 return false
332341 }
333342 return false
0 commit comments