diff --git a/src/backend/distributed/planner/multi_logical_optimizer.c b/src/backend/distributed/planner/multi_logical_optimizer.c index f93312779..52db3da29 100644 --- a/src/backend/distributed/planner/multi_logical_optimizer.c +++ b/src/backend/distributed/planner/multi_logical_optimizer.c @@ -2896,7 +2896,9 @@ GetAggregateType(Oid aggFunctionId) } aggregateCount = lengthof(AggregateNames); - for (aggregateIndex = 0; aggregateIndex < aggregateCount; aggregateIndex++) + + Assert(AGGREGATE_INVALID_FIRST == 0); + for (aggregateIndex = 1; aggregateIndex < aggregateCount; aggregateIndex++) { const char *aggregateName = AggregateNames[aggregateIndex]; if (strncmp(aggregateName, aggregateProcName, NAMEDATALEN) == 0) diff --git a/src/test/regress/expected/multi_simple_queries.out b/src/test/regress/expected/multi_simple_queries.out index 7a158efc2..f77983520 100644 --- a/src/test/regress/expected/multi_simple_queries.out +++ b/src/test/regress/expected/multi_simple_queries.out @@ -544,7 +544,6 @@ COPY articles_single_shard TO stdout; DEBUG: Creating router plan DEBUG: Plan is router executable 50 10 anjanette 19519 --- error out for queries with aggregates SELECT avg(word_count) FROM articles WHERE author_id = 2; @@ -556,6 +555,16 @@ DETAIL: distribution column value: 2 12356.400000000000 (1 row) +-- error out on unsupported aggregate +SET client_min_messages to 'NOTICE'; +CREATE AGGREGATE public.invalid(int) ( + sfunc = int4pl, + stype = int +); +SELECT invalid(word_count) FROM articles; +ERROR: unsupported aggregate function invalid +DROP AGGREGATE invalid(int); +SET client_min_messages to 'DEBUG2'; -- max, min, sum, count is somehow implemented -- differently in distributed planning SELECT max(word_count) as max, min(word_count) as min, diff --git a/src/test/regress/expected/multi_simple_queries_0.out b/src/test/regress/expected/multi_simple_queries_0.out index 5e5329b4e..cd11339c2 100644 --- a/src/test/regress/expected/multi_simple_queries_0.out +++ b/src/test/regress/expected/multi_simple_queries_0.out @@ -488,7 +488,6 @@ COPY articles_single_shard TO stdout; DEBUG: Creating router plan DEBUG: Plan is router executable 50 10 anjanette 19519 --- error out for queries with aggregates SELECT avg(word_count) FROM articles WHERE author_id = 2; @@ -500,6 +499,16 @@ DETAIL: distribution column value: 2 12356.400000000000 (1 row) +-- error out on unsupported aggregate +SET client_min_messages to 'NOTICE'; +CREATE AGGREGATE public.invalid(int) ( + sfunc = int4pl, + stype = int +); +SELECT invalid(word_count) FROM articles; +ERROR: unsupported aggregate function invalid +DROP AGGREGATE invalid(int); +SET client_min_messages to 'DEBUG2'; -- max, min, sum, count is somehow implemented -- differently in distributed planning SELECT max(word_count) as max, min(word_count) as min, diff --git a/src/test/regress/sql/multi_simple_queries.sql b/src/test/regress/sql/multi_simple_queries.sql index 8a03f06c9..7b4606b51 100644 --- a/src/test/regress/sql/multi_simple_queries.sql +++ b/src/test/regress/sql/multi_simple_queries.sql @@ -271,11 +271,24 @@ SELECT id -- copying from a single shard table does not require the master query COPY articles_single_shard TO stdout; --- error out for queries with aggregates SELECT avg(word_count) FROM articles WHERE author_id = 2; +-- error out on unsupported aggregate +SET client_min_messages to 'NOTICE'; + +CREATE AGGREGATE public.invalid(int) ( + sfunc = int4pl, + stype = int +); + +SELECT invalid(word_count) FROM articles; + +DROP AGGREGATE invalid(int); + +SET client_min_messages to 'DEBUG2'; + -- max, min, sum, count is somehow implemented -- differently in distributed planning SELECT max(word_count) as max, min(word_count) as min, @@ -313,5 +326,4 @@ SELECT * FROM articles TABLESAMPLE BERNOULLI (0) WHERE author_id = 1; SELECT * FROM articles TABLESAMPLE SYSTEM (100) WHERE author_id = 1 ORDER BY id; SELECT * FROM articles TABLESAMPLE BERNOULLI (100) WHERE author_id = 1 ORDER BY id; - SET client_min_messages to 'NOTICE';