Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-9228

Improve PosgtreSQL query plan for multi fulltext search

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 5.5
    • Fix Version/s: 5.4.2-HF21, 5.5.0-HF07, 5.6-RC1, 5.6
    • Component/s: Core VCS
    • Environment:
      PostgreSQL

      Description

      When searching on multiple fulltext field with an OR, the PosgreSQL query planner don't use the fulltext index.
      This is a performance issue.
      The reason is due to a PostgreSQL 9.1 bug that will be fixed in 9.2 but not backported in 9.1.

      The work around is to rewrite the query from:

      SELECT hierarchy.id
        FROM hierarchy
        JOIN fulltext ON fulltext.id = hierarchy.id,
        TO_TSQUERY('whatever1') query1,
        TO_TSQUERY('whatever2') query2
        WHERE (query1 @@ nx_to_tsvector(fulltext.fulltext))
           OR (query2 @@ nx_to_tsvector(fulltext.fulltext_title));
      

      to

      SELECT hierarchy.id
        FROM hierarchy
        JOIN fulltext ON fulltext.id = hierarchy.id
        WHERE (TO_TSQUERY('whatever1') @@ nx_to_tsvector(fulltext.fulltext))
           OR (TO_TSQUERY('whatever2') @@ nx_to_tsvector(fulltext.fulltext_title));
      

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 4 hours
                4h
                Remaining:
                Remaining Estimate - 4 hours
                4h
                Logged:
                Time Spent - Not Specified
                Not Specified