mirror of
https://github.com/postgres/postgres.git
synced 2025-07-09 22:41:56 +03:00
Use abbreviated keys for faster sorting of text datums.
This commit extends the SortSupport infrastructure to allow operator classes the option to provide abbreviated representations of Datums; in the case of text, we abbreviate by taking the first few characters of the strxfrm() blob. If the abbreviated comparison is insufficent to resolve the comparison, we fall back on the normal comparator. This can be much faster than the old way of doing sorting if the first few bytes of the string are usually sufficient to resolve the comparison. There is the potential for a performance regression if all of the strings to be sorted are identical for the first 8+ characters and differ only in later positions; therefore, the SortSupport machinery now provides an infrastructure to abort the use of abbreviation if it appears that abbreviation is producing comparatively few distinct keys. HyperLogLog, a streaming cardinality estimator, is included in this commit and used to make that determination for text. Peter Geoghegan, reviewed by me.
This commit is contained in:
@ -229,6 +229,14 @@ MJExamineQuals(List *mergeclauses,
|
||||
elog(ERROR, "cannot merge using non-equality operator %u",
|
||||
qual->opno);
|
||||
|
||||
/*
|
||||
* sortsupport routine must know if abbreviation optimization is
|
||||
* applicable in principle. It is never applicable for merge joins
|
||||
* because there is no convenient opportunity to convert to alternative
|
||||
* representation.
|
||||
*/
|
||||
clause->ssup.abbreviate = false;
|
||||
|
||||
/* And get the matching support or comparison function */
|
||||
Assert(clause->ssup.comparator == NULL);
|
||||
sortfunc = get_opfamily_proc(opfamily,
|
||||
|
Reference in New Issue
Block a user