Skip to content

Commit

Permalink
Merge dc1ec9c into 304cd8f
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmp85 committed Jan 16, 2015
2 parents 304cd8f + dc1ec9c commit 5839a35
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
15 changes: 15 additions & 0 deletions expected/queries.out
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ SELECT COUNT(*) FROM articles;
50
(1 row)

-- try query with more SQL features
SELECT author_id, sum(word_count) AS corpus_size FROM articles
GROUP BY author_id
HAVING sum(word_count) > 25000
Expand All @@ -189,6 +190,20 @@ SELECT author_id, sum(word_count) AS corpus_size FROM articles
6 | 50867
(5 rows)

-- use HAVING without its variable in target list
SELECT author_id FROM articles
GROUP BY author_id
HAVING sum(word_count) > 50000
ORDER BY author_id;
author_id
-----------
2
4
6
8
10
(5 rows)

-- verify temp tables used by cross-shard queries do not persist
SELECT COUNT(*) FROM pg_class WHERE relname LIKE 'pg_shard_temp_table%' AND
relkind = 'r';
Expand Down
8 changes: 7 additions & 1 deletion pg_shard.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ RowAndColumnFilterQuery(Query *query)
List *whereClauseList = NIL;
List *whereClauseColumnList = NIL;
List *projectColumnList = NIL;
List *havingClauseColumnList = NIL;
List *columnList = NIL;
ListCell *columnCell = NULL;
List *uniqueColumnList = NIL;
Expand All @@ -670,7 +671,12 @@ RowAndColumnFilterQuery(Query *query)
placeHolderBehavior);
projectColumnList = pull_var_clause((Node *) query->targetList, aggregateBehavior,
placeHolderBehavior);
columnList = list_union(whereClauseColumnList, projectColumnList);
havingClauseColumnList = pull_var_clause(query->havingQual, aggregateBehavior,
placeHolderBehavior);

columnList = list_concat(columnList, whereClauseColumnList);
columnList = list_concat(columnList, projectColumnList);
columnList = list_concat(columnList, havingClauseColumnList);

/*
* list_union() filters duplicates, but only between the lists. For example,
Expand Down
7 changes: 7 additions & 0 deletions sql/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,19 @@ SELECT * FROM articles WHERE author_id IN (SELECT id FROM authors WHERE name LIK
-- test cross-shard queries
SELECT COUNT(*) FROM articles;

-- try query with more SQL features
SELECT author_id, sum(word_count) AS corpus_size FROM articles
GROUP BY author_id
HAVING sum(word_count) > 25000
ORDER BY sum(word_count) DESC
LIMIT 5;

-- use HAVING without its variable in target list
SELECT author_id FROM articles
GROUP BY author_id
HAVING sum(word_count) > 50000
ORDER BY author_id;

-- verify temp tables used by cross-shard queries do not persist
SELECT COUNT(*) FROM pg_class WHERE relname LIKE 'pg_shard_temp_table%' AND
relkind = 'r';
Expand Down

0 comments on commit 5839a35

Please sign in to comment.