You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Assume a simple table distributed along an id column:
CREATETABLEemployees (
id integer,
name text
);
SELECT master_create_distributed_table('employees', 'id');
SELECT master_create_worker_shards('employees', 2, 1);
Using HAVING clauses in SELECT queries works correctly so long as columns referenced in the HAVING clause are in a WHERE, ORDER BY, or GROUP BY clause:
SELECT substr(name, 1, 1) AS init,
sum(id) AS id_total
FROM employees
GROUP BY init
HAVINGSUM(id) >200000;
# ┌──────┬──────────┐# │ init │ id_total │# ├──────┼──────────┤# │ H │ 319464 │# │ M │ 1253983 │# │ J │ 844768 │# │ V │ 280801 │# │ R │ 610906 │# │ L │ 1166332 │# │ D │ 829092 │# │ T │ 700698 │# │ I │ 201319 │# │ F │ 284724 │# │ N │ 363474 │# │ G │ 401067 │# │ E │ 697631 │# │ B │ 526513 │# │ C │ 1148864 │# │ S │ 1010327 │# │ P │ 244061 │# │ K │ 748454 │# │ A │ 1079310 │# └──────┴──────────┘# (19 rows)
But if columns in the HAVING clause do not appear elsewhere, the query returns incorrect results:
SELECT substr(name, 1, 1) AS init
FROM employees
GROUP BY init
HAVINGSUM(id) >200000;
# ┌──────┐# │ init │# ├──────┤# └──────┘# (0 rows)
This is probably related to #33, since it appears pg_shard currently only considers quals and projections in deciding which columns to retrieve from the remote. The HAVING clause is evaluated locally, so if its columns are not retrieved it cannot be evaluated correctly.
We should either reject the use of HAVING or make sure it has the columns it needs.
The text was updated successfully, but these errors were encountered:
Assume a simple table distributed along an
id
column:Using
HAVING
clauses inSELECT
queries works correctly so long as columns referenced in theHAVING
clause are in aWHERE
,ORDER BY
, orGROUP BY
clause:But if columns in the
HAVING
clause do not appear elsewhere, the query returns incorrect results:This is probably related to #33, since it appears
pg_shard
currently only considers quals and projections in deciding which columns to retrieve from the remote. TheHAVING
clause is evaluated locally, so if its columns are not retrieved it cannot be evaluated correctly.We should either reject the use of
HAVING
or make sure it has the columns it needs.The text was updated successfully, but these errors were encountered: