MCPcopy
hub / github.com/pingcap/tidb / GenIndexKey

Method GenIndexKey

pkg/table/tables/index.go:96–122  ·  view source on GitHub ↗

GenIndexKey generates storage key for index values. Returned distinct indicates whether the indexed values should be distinct in storage (i.e. whether handle is encoded in the key).

(ec errctx.Context, loc *time.Location, indexedValues []types.Datum, h kv.Handle, buf []byte)

Source from the content-addressed store, hash-verified

94// GenIndexKey generates storage key for index values. Returned distinct indicates whether the
95// indexed values should be distinct in storage (i.e. whether handle is encoded in the key).
96func (c *index) GenIndexKey(ec errctx.Context, loc *time.Location, indexedValues []types.Datum, h kv.Handle, buf []byte) (key []byte, distinct bool, err error) {
97 idxTblID := c.phyTblID
98 fullHandle := h
99 if c.idxInfo.Global {
100 idxTblID = c.tblInfo.ID
101 pi := c.tblInfo.GetPartitionInfo()
102 if pi != nil && pi.NewTableID != 0 {
103 isNew, ok := pi.DDLChangedIndex[c.idxInfo.ID]
104 if ok && isNew {
105 idxTblID = pi.NewTableID
106 }
107 }
108
109 if _, ok := fullHandle.(kv.PartitionHandle); !ok &&
110 c.idxInfo.GlobalIndexVersion >= model.GlobalIndexVersionV1 {
111 fullHandle = kv.NewPartitionHandle(c.phyTblID, h)
112 }
113 }
114
115 if err = c.castIndexValuesToChangingTypes(indexedValues); err != nil {
116 return
117 }
118
119 key, distinct, err = tablecodec.GenIndexKey(loc, c.tblInfo, c.idxInfo, idxTblID, indexedValues, fullHandle, buf)
120 err = ec.HandleError(err)
121 return
122}
123
124// GenIndexValue generates the index value.
125func (c *index) GenIndexValue(ec errctx.Context, loc *time.Location, distinct, untouched bool, indexedValues []types.Datum,

Callers 3

createMethod · 0.95
DeleteMethod · 0.95
ExistMethod · 0.95

Calls 5

NewPartitionHandleFunction · 0.92
GenIndexKeyFunction · 0.92
GetPartitionInfoMethod · 0.80
HandleErrorMethod · 0.45

Tested by

no test coverage detected