Queries that contain multiple etx_contains() operators
If you specify the etx_contains() operator in a query, the operator must be able to scan the index. If you execute a query and no etx index is available, the module returns an error.
lemon
zest
or ingredients that include orange rind
.
Two separate etx_contains() operators must be used
in the query. Unfortunately, the following type of query returns an
error because the database server cannot use a single index scan for
the two etx_contains() operators: SELECT id FROM recipes
WHERE etx_contains(recipe, Row ('lemon zest', 'SEARCH_TYPE = PHRASE_EXACT'))
OR
etx_contains(ingredients, Row ('orange rind', 'SEARCH_TYPE = PHRASE_EXACT'));
SELECT id FROM recipes
WHERE etx_contains(recipe, Row ('lemon zest', 'SEARCH_TYPE = PHRASE_EXACT'))
UNION
SELECT id FROM recipes
WHERE etx_contains(ingredients, Row ('orange rind', 'SEARCH_TYPE = PHRASE_EXACT'));
SELECT id FROM recipes
WHERE etx_contains(recipe, Row ('lemon zest', 'SEARCH_TYPE = PHRASE_EXACT'))
AND id IN
(SELECT id FROM recipes
WHERE etx_contains(ingredients, Row ('orange rind', 'SEARCH_TYPE = PHRASE_EXACT')));
The query plan for this type of query shows a semi-join of the result of the two index scans. Another alternative is to use two table aliases for the same table and to join the table to itself through a unique column.
It is possible to execute multiple etx_contains() operators against more than one column in the same or multiple tables as long as you do not specify them in the same WHERE clause. Examine the query plan to make sure that the database server has selected index scans for the etx_contains() operator.