mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Skip checking of scan keys required for directional scan in B-tree
Currently, B-tree code matches every scan key to every item on the page. Imagine the ordered B-tree scan for the query like this. SELECT * FROM tbl WHERE col > 'a' AND col < 'b' ORDER BY col; The (col > 'a') scan key will be always matched once we find the location to start the scan. The (col < 'b') scan key will match every item on the page as long as it matches the last item on the page. This patch implements prechecking of the scan keys required for directional scan on beginning of page scan. If precheck is successful we can skip this scan keys check for the items on the page. That could lead to significant acceleration especially if the comparison operator is expensive. Idea from patch by Konstantin Knizhnik. Discussion: https://postgr.es/m/079c3f8e-3371-abe2-e93c-fc8a0ae3f571%40garret.ru Reviewed-by: Peter Geoghegan, Pavel Borisov
This commit is contained in:
@ -1056,6 +1056,9 @@ typedef struct BTScanOpaqueData
|
||||
int *killedItems; /* currPos.items indexes of killed items */
|
||||
int numKilled; /* number of currently stored items */
|
||||
|
||||
/* flag indicating the first page in the scan */
|
||||
bool firstPage;
|
||||
|
||||
/*
|
||||
* If we are doing an index-only scan, these are the tuple storage
|
||||
* workspaces for the currPos and markPos respectively. Each is of size
|
||||
@ -1255,7 +1258,8 @@ extern void _bt_mark_array_keys(IndexScanDesc scan);
|
||||
extern void _bt_restore_array_keys(IndexScanDesc scan);
|
||||
extern void _bt_preprocess_keys(IndexScanDesc scan);
|
||||
extern bool _bt_checkkeys(IndexScanDesc scan, IndexTuple tuple,
|
||||
int tupnatts, ScanDirection dir, bool *continuescan);
|
||||
int tupnatts, ScanDirection dir, bool *continuescan,
|
||||
bool requiredMatchedByPrecheck);
|
||||
extern void _bt_killitems(IndexScanDesc scan);
|
||||
extern BTCycleId _bt_vacuum_cycleid(Relation rel);
|
||||
extern BTCycleId _bt_start_vacuum(Relation rel);
|
||||
|
Reference in New Issue
Block a user