I am disappointed with query performance: (Community Edition 6.5.1 build 6299)
it taking 2.1 seconds to find less than 4500 docs from a bucket, see the output below.
Whats wrong? how can i improve the performance?
Now I am worried because day by day my bucket will increase…so how can i fix this issue?
If i cant fix it then i must switch back to mysql…
In CE query service uses 4 cores only.
Your query requires ORDER BY which requires produce all possible values (even Fetch because it is not covered) and perform sort.
CREATE INDEX ix1 ON (cid, serial DESC, status) WHERE type = “account_head”;
This can avoid sort but with extra over head on indexer because it needs to scan serial, status. But may worth it to reduce fetch.
SELECT
a.aid
,a.name
,a.description
,a.ledger
,a.balance
,a.baltype
,a.status
,a.create_date
,g.name as group_name
,g.group_type
FROM master_erp a
LEFT JOIN master_erp g ON a.account_group=META(g).id AND g.type=“account_group”
WHERE a.type=“account_head” AND a.status IN[0,1] AND a.cid=“company::2” AND REGEXP_CONTAINS(a.ledger, “91001145”) ORDER BY a.serial DESC LIMIT 10 OFFSET 0;
REGEXP_CONTAINS(a.ledger, “91001145”) has dynamic value. Those will applied in side query. you will not able to define in the index key unless all the queries has 91001145
Please note nothing will fail. The values will not push to indexer. It will use other fields to get the document sand apply filter later. ie regexp_contains is treated as post index scan filter.
CREATE INDEX ix1 ON master_erp (cid, serial DESC, status) WHERE type = “account_head”;
SELECT * FROM master_erp
WHERE a.type=“account_head” AND a.status = 1 AND a.cid=“company::2” AND REGEXP_CONTAINS(a.ledger, “91001145”) ORDER BY a.serial DESC LIMIT 10 OFFSET 0;
Do EXPALIN and look IndexScan section.
IndexScan uses cid=“company::2”, status = 1 and produces all document keys
Then Fetches documents
Then apply the Filters including REGEXP_CONTAINS Further eliminates