@@ -111,6 +111,18 @@ func (ef *execFactory) ConstructLiteralValues(
111111 }
112112}
113113
114+ // recordIndexRead - if applicable - records the fact that the given index has
115+ // been used for reading.
116+ func (ef * execFactory ) recordIndexRead (tabDesc catalog.TableDescriptor , idx catalog.Index ) {
117+ if ! ef .isExplain && ! ef .planner .SessionData ().Internal {
118+ idxUsageKey := roachpb.IndexUsageKey {
119+ TableID : roachpb .TableID (tabDesc .GetID ()),
120+ IndexID : roachpb .IndexID (idx .GetID ()),
121+ }
122+ ef .planner .extendedEvalCtx .indexUsageStats .RecordRead (idxUsageKey )
123+ }
124+ }
125+
114126// ConstructScan is part of the exec.Factory interface.
115127func (ef * execFactory ) ConstructScan (
116128 table cat.Table , index cat.Index , params exec.ScanParams , reqOrdering exec.OutputOrdering ,
@@ -158,13 +170,7 @@ func (ef *execFactory) ConstructScan(
158170 scan .lockingWaitPolicy = descpb .ToScanLockingWaitPolicy (params .Locking .WaitPolicy )
159171 scan .lockingDurability = descpb .ToScanLockingDurability (params .Locking .Durability )
160172 scan .localityOptimized = params .LocalityOptimized
161- if ! ef .isExplain && ! ef .planner .SessionData ().Internal {
162- idxUsageKey := roachpb.IndexUsageKey {
163- TableID : roachpb .TableID (tabDesc .GetID ()),
164- IndexID : roachpb .IndexID (idx .GetID ()),
165- }
166- ef .planner .extendedEvalCtx .indexUsageStats .RecordRead (idxUsageKey )
167- }
173+ ef .recordIndexRead (tabDesc , idx )
168174
169175 return scan , nil
170176}
@@ -693,19 +699,12 @@ func (ef *execFactory) ConstructIndexJoin(
693699 }
694700
695701 idx := tabDesc .GetPrimaryIndex ()
702+ ef .recordIndexRead (tabDesc , idx )
696703 fetch .index = idx
697704 fetch .lockingStrength = descpb .ToScanLockingStrength (locking .Strength )
698705 fetch .lockingWaitPolicy = descpb .ToScanLockingWaitPolicy (locking .WaitPolicy )
699706 fetch .lockingDurability = descpb .ToScanLockingDurability (locking .Durability )
700707
701- if ! ef .isExplain && ! ef .planner .SessionData ().Internal {
702- idxUsageKey := roachpb.IndexUsageKey {
703- TableID : roachpb .TableID (tabDesc .GetID ()),
704- IndexID : roachpb .IndexID (idx .GetID ()),
705- }
706- ef .planner .extendedEvalCtx .indexUsageStats .RecordRead (idxUsageKey )
707- }
708-
709708 n := & indexJoinNode {
710709 singleInputPlanNode : singleInputPlanNode {input .(planNode )},
711710 columns : fetch .columns ,
@@ -756,19 +755,12 @@ func (ef *execFactory) ConstructLookupJoin(
756755 return nil , err
757756 }
758757
758+ ef .recordIndexRead (tabDesc , idx )
759759 fetch .index = idx
760760 fetch .lockingStrength = descpb .ToScanLockingStrength (locking .Strength )
761761 fetch .lockingWaitPolicy = descpb .ToScanLockingWaitPolicy (locking .WaitPolicy )
762762 fetch .lockingDurability = descpb .ToScanLockingDurability (locking .Durability )
763763
764- if ! ef .isExplain && ! ef .planner .SessionData ().Internal {
765- idxUsageKey := roachpb.IndexUsageKey {
766- TableID : roachpb .TableID (tabDesc .GetID ()),
767- IndexID : roachpb .IndexID (idx .GetID ()),
768- }
769- ef .planner .extendedEvalCtx .indexUsageStats .RecordRead (idxUsageKey )
770- }
771-
772764 n := & lookupJoinNode {
773765 singleInputPlanNode : singleInputPlanNode {input .(planNode )},
774766 lookupJoinPlanningInfo : lookupJoinPlanningInfo {
@@ -893,19 +885,12 @@ func (ef *execFactory) ConstructInvertedJoin(
893885 if err := fetch .initDescDefaults (tabDesc , colCfg ); err != nil {
894886 return nil , err
895887 }
888+ ef .recordIndexRead (tabDesc , idx )
896889 fetch .index = idx
897890 fetch .lockingStrength = descpb .ToScanLockingStrength (locking .Strength )
898891 fetch .lockingWaitPolicy = descpb .ToScanLockingWaitPolicy (locking .WaitPolicy )
899892 fetch .lockingDurability = descpb .ToScanLockingDurability (locking .Durability )
900893
901- if ! ef .isExplain && ! ef .planner .SessionData ().Internal {
902- idxUsageKey := roachpb.IndexUsageKey {
903- TableID : roachpb .TableID (tabDesc .GetID ()),
904- IndexID : roachpb .IndexID (idx .GetID ()),
905- }
906- ef .planner .extendedEvalCtx .indexUsageStats .RecordRead (idxUsageKey )
907- }
908-
909894 n := & invertedJoinNode {
910895 singleInputPlanNode : singleInputPlanNode {input .(planNode )},
911896 invertedJoinPlanningInfo : invertedJoinPlanningInfo {
@@ -966,22 +951,15 @@ func (ef *execFactory) constructFetchForZigzag(
966951 return fetchPlanningInfo {}, nil , err
967952 }
968953
969- tableDesc := table .(* optTable ).desc
970- idxDesc := index .(* optIndex ).idx
954+ tabDesc := table .(* optTable ).desc
955+ idx := index .(* optIndex ).idx
971956 var fetch fetchPlanningInfo
972- if err := fetch .initDescDefaults (tableDesc , colCfg ); err != nil {
957+ if err := fetch .initDescDefaults (tabDesc , colCfg ); err != nil {
973958 return fetchPlanningInfo {}, nil , err
974959 }
975960
976- if ! ef .isExplain && ! ef .planner .SessionData ().Internal {
977- idxUsageKey := roachpb.IndexUsageKey {
978- TableID : roachpb .TableID (tableDesc .GetID ()),
979- IndexID : roachpb .IndexID (idxDesc .GetID ()),
980- }
981- ef .planner .extendedEvalCtx .indexUsageStats .RecordRead (idxUsageKey )
982- }
983-
984- fetch .index = idxDesc
961+ ef .recordIndexRead (tabDesc , idx )
962+ fetch .index = idx
985963 fetch .lockingStrength = descpb .ToScanLockingStrength (locking .Strength )
986964 fetch .lockingWaitPolicy = descpb .ToScanLockingWaitPolicy (locking .WaitPolicy )
987965 fetch .lockingDurability = descpb .ToScanLockingDurability (locking .Durability )
@@ -2068,23 +2046,24 @@ func (ef *execFactory) ConstructVectorSearch(
20682046 targetNeighborCount uint64 ,
20692047) (exec.Node , error ) {
20702048 tabDesc := table .(* optTable ).desc
2071- indexDesc := index .(* optIndex ).idx
2049+ idx := index .(* optIndex ).idx
20722050 cols := makeColList (table , outCols )
20732051 resultCols := colinfo .ResultColumnsFromColumns (tabDesc .GetID (), cols )
20742052
20752053 // Encode the prefix constraint as a list of roachpb.Keys.
20762054 var sb span.Builder
20772055 sb .InitAllowingExternalRowData (
2078- ef .planner .EvalContext (), ef .planner .ExecCfg ().Codec , tabDesc , indexDesc ,
2056+ ef .planner .EvalContext (), ef .planner .ExecCfg ().Codec , tabDesc , idx ,
20792057 )
20802058 prefixKeys , err := sb .KeysFromVectorPrefixConstraint (ef .ctx , prefixConstraint )
20812059 if err != nil {
20822060 return nil , err
20832061 }
2062+ ef .recordIndexRead (tabDesc , idx )
20842063 return & vectorSearchNode {
20852064 vectorSearchPlanningInfo : vectorSearchPlanningInfo {
20862065 table : tabDesc ,
2087- index : indexDesc ,
2066+ index : idx ,
20882067 prefixKeys : prefixKeys ,
20892068 queryVector : queryVector ,
20902069 targetNeighborCount : targetNeighborCount ,
@@ -2115,11 +2094,14 @@ func (ef *execFactory) ConstructVectorMutationSearch(
21152094 cols = append (cols , colinfo.ResultColumn {Name : "quantized-vector" , Typ : types .Bytes })
21162095 }
21172096
2097+ tabDesc := table .(* optTable ).desc
2098+ idx := index .(* optIndex ).idx
2099+ ef .recordIndexRead (tabDesc , idx )
21182100 return & vectorMutationSearchNode {
21192101 singleInputPlanNode : singleInputPlanNode {input : inputPlan },
21202102 vectorMutationSearchPlanningInfo : vectorMutationSearchPlanningInfo {
2121- table : table .( * optTable ). desc ,
2122- index : index .( * optIndex ). idx ,
2103+ table : tabDesc ,
2104+ index : idx ,
21232105 prefixKeyCols : prefixKeyCols ,
21242106 queryVectorCol : queryVectorCol ,
21252107 suffixKeyCols : suffixKeyCols ,
0 commit comments