LP#1775958: Rework pullup mechanism to flatten more nested queries
authorMike Rylander <mrylander@gmail.com>
Fri, 12 Oct 2018 18:43:26 +0000 (14:43 -0400)
committerJason Stephenson <jason@sigio.com>
Wed, 8 Feb 2023 18:03:50 +0000 (13:03 -0500)
commit754cc821017487768e44d59cfd9b76ab66873a15
tree72628b9ed10faf30c990c96be84bec9ea77de76d
parent9028d68460083168a0919b1e9499cf23ac431e52
LP#1775958: Rework pullup mechanism to flatten more nested queries

The bulk of this commit reworks the query tree pullup logic, which is
responsible for simplifying the query tree that is used to generate the
SQL query for search.  In particular, we now do a better job of finding
opportunities to merge adjacent parts of the query that have the same
requested_class (pre-dealiasing) in the face of boolean OR operators,
explicit grouping, and alternating requested_class values.  The result
is fewer joins in the SQL, which should speed up all but the most
trivial searches, and generally help protect the database from mis- or
mal-constructed queries.  We also now use CTEs to separate branches of
the logical search tree into descrete subqueries, which helps reduce
the total core query JOINs, and provides the planner with more options
for join order.

This also does away with the conversion of a negated atom into an
"un-phrase".  Instead, we just detect and handle those directly as atoms
with a prefix, as appropriate.  This allows single negated words to be
used directly in the core tsquery construct, rather than having them
require a separate join and special where clause.

Additionally, this commit handles phrases differently at both the QP and
SQL level, making use of Postgres's phrase support in modern versions
and simplifying how they're handled within the base parse tree
structure.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Jason Stephenson <jason@sigio.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/QueryParser.pm