@@ -82,7 +82,7 @@ func costedIndexScans(ctx *sql.Context, a *Analyzer, n sql.Node, qFlags *sql.Que
8282 }
8383 }
8484 if iat , ok := rt .UnderlyingTable ().(sql.IndexAddressableTable ); ok {
85- return costedIndexLookup (ctx , n , a . Catalog , iat , rt , aliasName , filter .Expression , qFlags )
85+ return costedIndexLookup (ctx , n , a , iat , rt , aliasName , filter .Expression , qFlags )
8686 }
8787 return n , transform .SameTree , nil
8888 })
@@ -123,19 +123,24 @@ func indexSearchableLookup(n sql.Node, rt sql.TableNode, lookup sql.IndexLookup,
123123 return ret , transform .NewTree , nil
124124}
125125
126- func costedIndexLookup (ctx * sql.Context , n sql.Node , cat sql. Catalog , iat sql.IndexAddressableTable , rt sql.TableNode , aliasName string , oldFilter sql.Expression , qFlags * sql.QueryFlags ) (sql.Node , transform.TreeIdentity , error ) {
126+ func costedIndexLookup (ctx * sql.Context , n sql.Node , a * Analyzer , iat sql.IndexAddressableTable , rt sql.TableNode , aliasName string , oldFilter sql.Expression , qFlags * sql.QueryFlags ) (sql.Node , transform.TreeIdentity , error ) {
127127 indexes , err := iat .GetIndexes (ctx )
128128 if err != nil {
129129 return n , transform .SameTree , err
130130 }
131- ita , _ , filters , err := getCostedIndexScan (ctx , cat , rt , indexes , expression .SplitConjunction (oldFilter ), qFlags )
131+ ita , stats , filters , err := getCostedIndexScan (ctx , a . Catalog , rt , indexes , expression .SplitConjunction (oldFilter ), qFlags )
132132 if err != nil || ita == nil {
133133 return n , transform .SameTree , err
134134 }
135135 var ret sql.Node = ita
136136 if aliasName != "" {
137137 ret = plan .NewTableAlias (aliasName , ret )
138138 }
139+
140+ a .Log ("new indexed table: %s/%s/%s" , ita .Index ().Database (), ita .Index ().Table (), ita .Index ().ID ())
141+ a .Log ("index stats cnt: " , stats .RowCount ())
142+ a .Log ("index stats histogram" , stats .Histogram ().DebugString ())
143+
139144 // excluded from tree + not included in index scan => filter above scan
140145 if len (filters ) > 0 {
141146 ret = plan .NewFilter (expression .JoinAnd (filters ... ), ret )
@@ -1305,6 +1310,7 @@ func indexHasContentHashedFieldForFilter(filter *iScanLeaf, idx sql.Index, ordin
13051310// by a statistic, returning the updated statistic, whether the filter was
13061311// applicable, and the maximum prefix key (0 or 1 for a leaf).
13071312func (c * indexCoster ) costIndexScanLeaf (filter * iScanLeaf , s sql.Statistic , buckets []sql.HistogramBucket , ordinals map [string ]int , idx sql.Index ) ([]sql.HistogramBucket , * sql.FuncDepSet , bool , int , error ) {
1313+ //todo use {underlyingTable}.{gf.Name}?
13081314 ord , ok := ordinals [strings .ToLower (filter .gf .Name ())]
13091315 if ! ok {
13101316 return nil , nil , false , 0 , nil
0 commit comments