Skip to content

Commit 5dbdb2f

Browse files
committed
Make tablesample work with partitioned tables.
This was an oversight in the original partitioning commit. Amit Langote, reviewed by David Fetter Discussion: http://postgr.es/m/59af6590-8ace-04c4-c36c-ea35d435c60e@lab.ntt.co.jp
1 parent 6d493e1 commit 5dbdb2f

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/backend/parser/parse_clause.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,8 @@ transformFromClauseItem(ParseState *pstate, Node *n,
907907
rte = rt_fetch(rtr->rtindex, pstate->p_rtable);
908908
/* We only support this on plain relations and matviews */
909909
if (rte->relkind != RELKIND_RELATION &&
910-
rte->relkind != RELKIND_MATVIEW)
910+
rte->relkind != RELKIND_MATVIEW &&
911+
rte->relkind != RELKIND_PARTITIONED_TABLE)
911912
ereport(ERROR,
912913
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
913914
errmsg("TABLESAMPLE clause can only be applied to tables and materialized views"),

src/test/regress/expected/tablesample.out

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,21 @@ SELECT q.* FROM (SELECT * FROM test_tablesample) as q TABLESAMPLE BERNOULLI (5);
313313
ERROR: syntax error at or near "TABLESAMPLE"
314314
LINE 1: ...CT q.* FROM (SELECT * FROM test_tablesample) as q TABLESAMPL...
315315
^
316+
-- check partitioned tables support tablesample
317+
create table parted_sample (a int) partition by list (a);
318+
create table parted_sample_1 partition of parted_sample for values in (1);
319+
create table parted_sample_2 partition of parted_sample for values in (2);
320+
explain (costs off)
321+
select * from parted_sample tablesample bernoulli (100);
322+
QUERY PLAN
323+
-------------------------------------------
324+
Append
325+
-> Sample Scan on parted_sample
326+
Sampling: bernoulli ('100'::real)
327+
-> Sample Scan on parted_sample_1
328+
Sampling: bernoulli ('100'::real)
329+
-> Sample Scan on parted_sample_2
330+
Sampling: bernoulli ('100'::real)
331+
(7 rows)
332+
333+
drop table parted_sample, parted_sample_1, parted_sample_2;

src/test/regress/sql/tablesample.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,11 @@ WITH query_select AS (SELECT * FROM test_tablesample)
100100
SELECT * FROM query_select TABLESAMPLE BERNOULLI (5.5) REPEATABLE (1);
101101

102102
SELECT q.* FROM (SELECT * FROM test_tablesample) as q TABLESAMPLE BERNOULLI (5);
103+
104+
-- check partitioned tables support tablesample
105+
create table parted_sample (a int) partition by list (a);
106+
create table parted_sample_1 partition of parted_sample for values in (1);
107+
create table parted_sample_2 partition of parted_sample for values in (2);
108+
explain (costs off)
109+
select * from parted_sample tablesample bernoulli (100);
110+
drop table parted_sample, parted_sample_1, parted_sample_2;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy