citus icon indicating copy to clipboard operation
citus copied to clipboard

Query: where t.value IN (1, 5,8,13.......) very very slow

Open Dawandevo opened this issue 10 years ago • 6 comments

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?

Dawandevo avatar Sep 10 '16 23:09 Dawandevo

[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.

ImreSamu avatar Sep 11 '16 00:09 ImreSamu

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

Dawandevo avatar Sep 11 '16 02:09 Dawandevo

@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?

ozgune avatar Sep 15 '16 17:09 ozgune

Query with IN (4 minutes with citus + cstore): Link to pastebin

inway

Query with ANY VALUES (8 seconds with citus + cstore): Link to pastebin

anyvalues

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 )

Dawandevo avatar Sep 20 '16 08:09 Dawandevo

@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

lfittl avatar Sep 22 '16 21:09 lfittl

Closed via #1475

velioglu avatar Aug 11 '17 07:08 velioglu