Summary:
Make use standard two-level ("might recheck" and "need recheck")
approach to recheck index conditions implemented in index access
methods. Index recheck is needed if index access implementation of
certain conditions is not strict enough to filter out all mismatches.
In other words, index scan may return extra rows and Postgres need to
evaluate condition again, after it has obtained the row from the table,
to filter out those extras.
In Yugabyte first level check can be checked before the scan
initialization is complete and normally used to create safer execution
plans (do not pushdown aggregates) if recheck may be required, or
otherwise optimize execution by skipping preparation of recheck
expressions. Second level is more accurate, but require scan ready for
execution. Basically, if "need recheck" is false, recheck is not
performed.
The bitmap scan has its specifics. Bitmap table scan generally has
multiple bitmap index scans, separated by bitmap AND or OR operations,
and all they are separate plan nodes. The "might recheck" and "need
recheck" conditions are checked by the index scan, and the results need
to be applied by the bitmap table scan, so logic was implemented to
communicate those results. While "might recheck" condition is an
attribute of the scan state node, the "need recheck" condition is an
attribute of the bitmap. The communication through AND or OR operations
is similar, but there are special cases around bitmaps: work mem
exceeded, empty bitmap.
Other notable change is that bitmap index scans are now labeled "index
only". That flag is important for the index access method to accurately
determine "need recheck" condition, and also simplified code to prepare
PgGate objects.
With regard to the flacky test reported in the GHI#26476, before "might_recheck"
fields were introduced, EXPLAIN showed the recheck clause based on current
"need_recheck" value, which was true or false depending if the last row required
recheck or not. So test result depended on row order.
Jira: DB-15844
Test Plan: ./yb_build.sh --java-test 'org.yb.pgsql.TestPgRegressYbBitmapScans#testPgRegressYbBitmapScans'
Reviewers: jason, telgersma
Reviewed By: telgersma
Subscribers: smishra, yql
Tags: #jenkins-ready
Differential Revision: https://phorge.dev.yugabyte.com/D43009