Efficient search expressions for background searches
In a background search, certain elements of the query must be considered for best performance.
Ordering internal search results by grouped properties
When you create a background search template in the administration console, you can select the Order internal search results by grouped properties property. Doing so causes the underlying database query that is run by Content Platform Engineto include an ORDER BY clause. The properties that are referenced by this clause are the grouped properties (the GROUP BY properties). Usually, this option is not needed since, by default, background search efficiently updates aggregations to the results table during processing of each page of search results.
- When the Order internal search results by grouped properties property is selected.
- When an explicit ORDER BY clause is used in a background search expression. You might want to use the ORDER BY clause to apply a wanted ORDER BY column to the underlying database query for purposes of performance tuning.
SELECT CustomerName as CustomerName,
COUNT(Id) as ObjectCount
FROM PurchaseOrders
GROUP BY CustomerNameCREATE UNIQUE INDEX I_TN_COVER3
ON (uxyz_CustomerName ASC, object_id ASC)
INCLUDE (security_id, home_id...)Add the remaining columns from the SELECT and WHERE clause into the index to cover the query. For DB2® and SQL Server databases, add the columns as INCLUDE columns. Name the index appropriately.
- Selecting the Order internal search results by grouped properties property
- Adding an explicit ORDER BY clause to the search expression
Following this rule helps to avoid the following problems with large covering indexes: degraded ingestion performance, large storage space requirements, and resource contention. Circumstances that might require an exception to the rule include query plans that result in poor performance or a need for a better index.
Adding an explicit ORDER BY property
SELECT CmRpt::FormatDate(DateCreated, 'MM/yyyy')
AS CmRptDate,
COUNT(Id) as CmRptObjectCount
FROM DocVersion
WHERE DateCreated > @StartDate@
AND DateCreated < @EndDate@
GROUP BY CmRptDate
ORDER BY DateCreated- A table scan
- The use of the primary key index to repetitively look up rows followed by applying the range conditions on the main table. This query can take a long time for a large table.
CREATE UNIQUE INDEX I_DV_COVER4
ON DocVersion (create_date ASC, object_id ASC)
INCLUDE (security_id, home_id...)Avoid using an asterisk in the COUNT() expression
SELECT COUNT(*) FROM DocumentSELECT COUNT(Id) FROM Document