Repository navigation
executor: add SkipScan to TableScan and IndexScan - #441
Conversation
SkipScan lets TiKV return only the first row, in scan order, of each group of rows sharing the same leading key columns, and skip the rest of the group. It serves loose index scans such as `SELECT a, MAX(b) FROM t GROUP BY a` on an index (a, b). Signed-off-by: Evan Zhou <coocood@gmail.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
What problem does this PR solve?
Problem Summary:
SELECT a, MAX(b) FROM t GROUP BY aon an index(a, b)reads every row of the index today, although only one row per distinctais needed. This PR adds the protocol for TiDB to ask TiKV for a loose index scan: return the first row of each group, then skip the rest of the group.What is changed and how it works?
What's Changed:
SkipScanwithprefix_column_counttoexecutor.proto.skip_scantoIndexScan(field 9) andTableScan(field 15). Both are only used by TiKV.go-tipb/executor.pb.gowithscripts/generate-go.sh, and updatescripts/proto.lock.How it Works:
prefix_column_countkey columns, plus whether the next key column is NULL. TiKV returns the first row of each group in scan order and skips the rest of the group.MAX(b)uses a backward scan: NULL sorts lowest, so the first row of a group holds the largestb.MIN(b)uses a forward scan: rows whosebis NULL form their own group, so the smallest non-NULLbis still returned.IndexScan, and the common handle columns forTableScan.skip_scankeeps the current behavior. A TiKV that does not know the field ignores it and returns every row, so TiDB must check that TiKV supports it before sending it.Checks:
scripts/generate-go.sh; the other generated Go files are unchangedgo build ./go-tipb/...andgo vet ./go-tipb/protolock status -lockdir=scripts -protoroot=protoRelated changes
pingcap/docs/pingcap/docs-cn: not neededSummary by CodeRabbit