Merge pull request #2332 from citusdata/tablesample

Support TABLESAMPLE in router queries
pull/2384/head
Marco Slot 2018-09-17 15:02:58 +02:00 committed by GitHub
commit e0942d9df5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 107 additions and 3 deletions

View File

@ -6916,6 +6916,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
deparse_columns *colinfo = deparse_columns_fetch(varno, dpns); deparse_columns *colinfo = deparse_columns_fetch(varno, dpns);
RangeTblFunction *rtfunc1 = NULL; RangeTblFunction *rtfunc1 = NULL;
bool printalias; bool printalias;
CitusRTEKind rteKind = GetRangeTblKind(rte);
if (rte->lateral) if (rte->lateral)
appendStringInfoString(buf, "LATERAL "); appendStringInfoString(buf, "LATERAL ");
@ -7135,9 +7136,12 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
} }
/* Tablesample clause must go after any alias */ /* Tablesample clause must go after any alias */
if (rte->rtekind == RTE_RELATION && rte->tablesample) if ((rteKind == CITUS_RTE_RELATION || rteKind == CITUS_RTE_SHARD) &&
rte->tablesample)
{
get_tablesample_def(rte->tablesample, context); get_tablesample_def(rte->tablesample, context);
} }
}
else if (IsA(jtnode, JoinExpr)) else if (IsA(jtnode, JoinExpr))
{ {
JoinExpr *j = (JoinExpr *) jtnode; JoinExpr *j = (JoinExpr *) jtnode;

View File

@ -6933,6 +6933,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
deparse_columns *colinfo = deparse_columns_fetch(varno, dpns); deparse_columns *colinfo = deparse_columns_fetch(varno, dpns);
RangeTblFunction *rtfunc1 = NULL; RangeTblFunction *rtfunc1 = NULL;
bool printalias; bool printalias;
CitusRTEKind rteKind = GetRangeTblKind(rte);
if (rte->lateral) if (rte->lateral)
appendStringInfoString(buf, "LATERAL "); appendStringInfoString(buf, "LATERAL ");
@ -7152,9 +7153,12 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
} }
/* Tablesample clause must go after any alias */ /* Tablesample clause must go after any alias */
if (rte->rtekind == RTE_RELATION && rte->tablesample) if ((rteKind == CITUS_RTE_RELATION || rteKind == CITUS_RTE_SHARD) &&
rte->tablesample)
{
get_tablesample_def(rte->tablesample, context); get_tablesample_def(rte->tablesample, context);
} }
}
else if (IsA(jtnode, JoinExpr)) else if (IsA(jtnode, JoinExpr))
{ {
JoinExpr *j = (JoinExpr *) jtnode; JoinExpr *j = (JoinExpr *) jtnode;

View File

@ -6660,6 +6660,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
deparse_columns *colinfo = deparse_columns_fetch(varno, dpns); deparse_columns *colinfo = deparse_columns_fetch(varno, dpns);
RangeTblFunction *rtfunc1 = NULL; RangeTblFunction *rtfunc1 = NULL;
bool printalias; bool printalias;
CitusRTEKind rteKind = GetRangeTblKind(rte);
if (rte->lateral) if (rte->lateral)
appendStringInfoString(buf, "LATERAL "); appendStringInfoString(buf, "LATERAL ");
@ -6876,9 +6877,12 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
} }
/* Tablesample clause must go after any alias */ /* Tablesample clause must go after any alias */
if (rte->rtekind == RTE_RELATION && rte->tablesample) if ((rteKind == CITUS_RTE_RELATION || rteKind == CITUS_RTE_SHARD) &&
rte->tablesample)
{
get_tablesample_def(rte->tablesample, context); get_tablesample_def(rte->tablesample, context);
} }
}
else if (IsA(jtnode, JoinExpr)) else if (IsA(jtnode, JoinExpr))
{ {
JoinExpr *j = (JoinExpr *) jtnode; JoinExpr *j = (JoinExpr *) jtnode;

View File

@ -615,4 +615,47 @@ SELECT count(*) FROM (
50 50
(1 row) (1 row)
-- tablesample is supported
SELECT * FROM articles TABLESAMPLE SYSTEM (0) WHERE author_id = 1;
DEBUG: Creating router plan
DEBUG: Plan is router executable
DETAIL: distribution column value: 1
id | author_id | title | word_count
----+-----------+-------+------------
(0 rows)
SELECT * FROM articles TABLESAMPLE BERNOULLI (0) WHERE author_id = 1;
DEBUG: Creating router plan
DEBUG: Plan is router executable
DETAIL: distribution column value: 1
id | author_id | title | word_count
----+-----------+-------+------------
(0 rows)
SELECT * FROM articles TABLESAMPLE SYSTEM (100) WHERE author_id = 1 ORDER BY id;
DEBUG: Creating router plan
DEBUG: Plan is router executable
DETAIL: distribution column value: 1
id | author_id | title | word_count
----+-----------+--------------+------------
1 | 1 | arsenous | 9572
11 | 1 | alamo | 1347
21 | 1 | arcading | 5890
31 | 1 | athwartships | 7271
41 | 1 | aznavour | 11814
(5 rows)
SELECT * FROM articles TABLESAMPLE BERNOULLI (100) WHERE author_id = 1 ORDER BY id;
DEBUG: Creating router plan
DEBUG: Plan is router executable
DETAIL: distribution column value: 1
id | author_id | title | word_count
----+-----------+--------------+------------
1 | 1 | arsenous | 9572
11 | 1 | alamo | 1347
21 | 1 | arcading | 5890
31 | 1 | athwartships | 7271
41 | 1 | aznavour | 11814
(5 rows)
SET client_min_messages to 'NOTICE'; SET client_min_messages to 'NOTICE';

View File

@ -559,4 +559,47 @@ SELECT count(*) FROM (
50 50
(1 row) (1 row)
-- tablesample is supported
SELECT * FROM articles TABLESAMPLE SYSTEM (0) WHERE author_id = 1;
DEBUG: Creating router plan
DEBUG: Plan is router executable
DETAIL: distribution column value: 1
id | author_id | title | word_count
----+-----------+-------+------------
(0 rows)
SELECT * FROM articles TABLESAMPLE BERNOULLI (0) WHERE author_id = 1;
DEBUG: Creating router plan
DEBUG: Plan is router executable
DETAIL: distribution column value: 1
id | author_id | title | word_count
----+-----------+-------+------------
(0 rows)
SELECT * FROM articles TABLESAMPLE SYSTEM (100) WHERE author_id = 1 ORDER BY id;
DEBUG: Creating router plan
DEBUG: Plan is router executable
DETAIL: distribution column value: 1
id | author_id | title | word_count
----+-----------+--------------+------------
1 | 1 | arsenous | 9572
11 | 1 | alamo | 1347
21 | 1 | arcading | 5890
31 | 1 | athwartships | 7271
41 | 1 | aznavour | 11814
(5 rows)
SELECT * FROM articles TABLESAMPLE BERNOULLI (100) WHERE author_id = 1 ORDER BY id;
DEBUG: Creating router plan
DEBUG: Plan is router executable
DETAIL: distribution column value: 1
id | author_id | title | word_count
----+-----------+--------------+------------
1 | 1 | arsenous | 9572
11 | 1 | alamo | 1347
21 | 1 | arcading | 5890
31 | 1 | athwartships | 7271
41 | 1 | aznavour | 11814
(5 rows)
SET client_min_messages to 'NOTICE'; SET client_min_messages to 'NOTICE';

View File

@ -296,4 +296,10 @@ SELECT count(*) FROM (
xmax IS NOT NULL xmax IS NOT NULL
) x; ) x;
-- tablesample is supported
SELECT * FROM articles TABLESAMPLE SYSTEM (0) WHERE author_id = 1;
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'; SET client_min_messages to 'NOTICE';