Query: where t.value IN (1, 5,8,13.......) very very slow
where t.value IN (1, 5,8,13.......) (about 2000 numbers)
is very very slow with postgres/citusdb.
unfortunately the workaround (link to blogentry) to replace the query with:
where t.value = ANY (values (1),(5),(8),(13)........
doesnt work with citus because of this error:
FEHLER: cannot perform distributed planning on this query DETAIL: Complex table expressions are currently unsupported
is it somehow possible to use the any values workaround in citusdb on distributed tables?
[maybe] see : https://github.com/citusdata/citus/issues/443
- it is worth to try the :
WHERE t.value = ANY(ARRAY[1,5,8,13,....])
According to the blogentry , it has a similar performance.
Update: this change need only be applied on 9.0. As of Postgres 9.3, ANY(ARRAY[...]) is performing properly again.
Tried it with ARRAY, no difference to IN
Query time of ANY VALUES variant is about 8 seconds (singleshard query)
IN and ANY ARRAY variant (have the same query plan) query time of 11 minutes
@dawuwu : Thanks for opening this issue. Could you provide a few more details on the performance you're observing? We find that the following details usually help in understanding more: example table schema and query, and data size.
I also had a clarification question. @ImreSamu pointed to the same blog entry that you linked to as well. Datadog's blog post notes at the end that this issue has been fixed in PostgreSQL 9.3+. Could you be trying this query with an earlier Postgres version?
Query with IN (4 minutes with citus + cstore): Link to pastebin
Query with ANY VALUES (8 seconds with citus + cstore): Link to pastebin
Schema (400m rows):
CREATE TABLE precalc_citus_cstore5 ( v1 integer NOT NULL, v2 double precision, yearweek integer, v7 integer, v3 character varying(80), v4 character varying(255), v5 integer, v6 double precision )
@dawuwu Two questions for clarification:
- Are you using any of Citus parallelization features in these plans, or is this just the cstore data from a single node?
- Could you post the full EXPLAIN output for the two plans above?
By the way, given you have a fairly lengthy list of values, it might make sense to create a temporary table with the values. You can find a similar approach described in the docs here: https://docs.citusdata.com/en/v5.2/reference/sql_workarounds.html#workaround-1-generate-explicit-where-in-expression
Closed via #1475