Skip to content

Commit 4118392

Browse files
author
Commitfest Bot
committed
[CF 5959] v3 - Import Statistics in postgres_fdw before resorting to sampling.
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5959 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/CADkLM=cVc-KUAqcm1yoDkGwMrcgCvxY3WAMpaRZVLtO9sbc+kg@mail.gmail.com Author(s): Corey Huinker
2 parents 50eb4e1 + 2613f7a commit 4118392

File tree

7 files changed

+746
-4
lines changed

7 files changed

+746
-4
lines changed

contrib/postgres_fdw/expected/postgres_fdw.out

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ INSERT INTO loct_empty
628628
SELECT id, 'AAA' || to_char(id, 'FM000') FROM generate_series(1, 100) id;
629629
DELETE FROM loct_empty;
630630
ANALYZE ft_empty;
631+
INFO: Found no remote statistics for "ft_empty"
631632
EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM ft_empty ORDER BY c1;
632633
QUERY PLAN
633634
-------------------------------------------------------------------------------
@@ -4551,7 +4552,8 @@ REINDEX TABLE reind_fdw_parent; -- ok
45514552
REINDEX TABLE CONCURRENTLY reind_fdw_parent; -- ok
45524553
DROP TABLE reind_fdw_parent;
45534554
-- ===================================================================
4554-
-- conversion error
4555+
-- conversion error, will generate a WARNING for imported stats and an
4556+
-- error on locally computed stats.
45554557
-- ===================================================================
45564558
ALTER FOREIGN TABLE ft1 ALTER COLUMN c8 TYPE int;
45574559
SELECT * FROM ft1 ftx(x1,x2,x3,x4,x5,x6,x7,x8) WHERE x1 = 1; -- ERROR
@@ -4568,6 +4570,9 @@ CONTEXT: whole-row reference to foreign table "ftx"
45684570
SELECT sum(c2), array_agg(c8) FROM ft1 GROUP BY c8; -- ERROR
45694571
ERROR: invalid input syntax for type integer: "foo"
45704572
CONTEXT: processing expression at position 2 in select list
4573+
ANALYZE ft1; -- WARNING
4574+
WARNING: invalid input syntax for type integer: "foo"
4575+
ALTER FOREIGN TABLE ft1 OPTIONS ( fetch_stats 'false' );
45714576
ANALYZE ft1; -- ERROR
45724577
ERROR: invalid input syntax for type integer: "foo"
45734578
CONTEXT: column "c8" of foreign table "ft1"
@@ -7102,6 +7107,7 @@ INSERT INTO loct2 VALUES (1002, 'bar');
71027107
CREATE FOREIGN TABLE remt2 (c1 int, c2 text) SERVER loopback OPTIONS (table_name 'loct2');
71037108
ANALYZE loct1;
71047109
ANALYZE remt2;
7110+
INFO: Found no remote statistics for "remt2"
71057111
SET enable_mergejoin TO false;
71067112
SET enable_hashjoin TO false;
71077113
SET enable_material TO false;
@@ -8784,6 +8790,7 @@ alter foreign table foo2 options (use_remote_estimate 'true');
87848790
create index i_loct1_f1 on loct1(f1);
87858791
create index i_foo_f1 on foo(f1);
87868792
analyze foo;
8793+
INFO: Found no remote statistics for "foo2"
87878794
analyze loct1;
87888795
-- inner join; expressions in the clauses appear in the equivalence class list
87898796
explain (verbose, costs off)
@@ -9013,7 +9020,9 @@ insert into remt1 values (2, 'bar');
90139020
insert into remt2 values (1, 'foo');
90149021
insert into remt2 values (2, 'bar');
90159022
analyze remt1;
9023+
INFO: Found no remote statistics for "remt1"
90169024
analyze remt2;
9025+
INFO: Found no remote statistics for "remt2"
90179026
explain (verbose, costs off)
90189027
update parent set b = parent.b || remt2.b from remt2 where parent.a = remt2.a returning *;
90199028
QUERY PLAN
@@ -10313,6 +10322,8 @@ CREATE FOREIGN TABLE ftprt1_p1 PARTITION OF fprt1 FOR VALUES FROM (0) TO (250)
1031310322
CREATE FOREIGN TABLE ftprt1_p2 PARTITION OF fprt1 FOR VALUES FROM (250) TO (500)
1031410323
SERVER loopback OPTIONS (TABLE_NAME 'fprt1_p2');
1031510324
ANALYZE fprt1;
10325+
INFO: Found no remote statistics for "ftprt1_p1"
10326+
INFO: Found no remote statistics for "ftprt1_p2"
1031610327
ANALYZE fprt1_p1;
1031710328
ANALYZE fprt1_p2;
1031810329
CREATE TABLE fprt2 (a int, b int, c varchar) PARTITION BY RANGE(b);
@@ -10328,6 +10339,8 @@ ALTER TABLE fprt2 ATTACH PARTITION ftprt2_p1 FOR VALUES FROM (0) TO (250);
1032810339
CREATE FOREIGN TABLE ftprt2_p2 PARTITION OF fprt2 FOR VALUES FROM (250) TO (500)
1032910340
SERVER loopback OPTIONS (table_name 'fprt2_p2', use_remote_estimate 'true');
1033010341
ANALYZE fprt2;
10342+
INFO: Found no remote statistics for "ftprt2_p1"
10343+
INFO: Found no remote statistics for "ftprt2_p2"
1033110344
ANALYZE fprt2_p1;
1033210345
ANALYZE fprt2_p2;
1033310346
-- inner join three tables
@@ -10515,9 +10528,15 @@ CREATE FOREIGN TABLE fpagg_tab_p1 PARTITION OF pagg_tab FOR VALUES FROM (0) TO (
1051510528
CREATE FOREIGN TABLE fpagg_tab_p2 PARTITION OF pagg_tab FOR VALUES FROM (10) TO (20) SERVER loopback OPTIONS (table_name 'pagg_tab_p2');
1051610529
CREATE FOREIGN TABLE fpagg_tab_p3 PARTITION OF pagg_tab FOR VALUES FROM (20) TO (30) SERVER loopback OPTIONS (table_name 'pagg_tab_p3');
1051710530
ANALYZE pagg_tab;
10531+
INFO: Found no remote statistics for "fpagg_tab_p1"
10532+
INFO: Found no remote statistics for "fpagg_tab_p2"
10533+
INFO: Found no remote statistics for "fpagg_tab_p3"
1051810534
ANALYZE fpagg_tab_p1;
10535+
INFO: Found no remote statistics for "fpagg_tab_p1"
1051910536
ANALYZE fpagg_tab_p2;
10537+
INFO: Found no remote statistics for "fpagg_tab_p2"
1052010538
ANALYZE fpagg_tab_p3;
10539+
INFO: Found no remote statistics for "fpagg_tab_p3"
1052110540
-- When GROUP BY clause matches with PARTITION KEY.
1052210541
-- Plan with partitionwise aggregates is disabled
1052310542
SET enable_partitionwise_aggregate TO false;
@@ -11463,6 +11482,8 @@ CREATE FOREIGN TABLE async_p2 PARTITION OF async_pt FOR VALUES FROM (2000) TO (3
1146311482
INSERT INTO async_p1 SELECT 1000 + i, i, to_char(i, 'FM0000') FROM generate_series(0, 999, 5) i;
1146411483
INSERT INTO async_p2 SELECT 2000 + i, i, to_char(i, 'FM0000') FROM generate_series(0, 999, 5) i;
1146511484
ANALYZE async_pt;
11485+
INFO: Found no remote statistics for "async_p1"
11486+
INFO: Found no remote statistics for "async_p2"
1146611487
-- simple queries
1146711488
CREATE TABLE result_tbl (a int, b int, c text);
1146811489
EXPLAIN (VERBOSE, COSTS OFF)
@@ -11569,6 +11590,9 @@ CREATE FOREIGN TABLE async_p3 PARTITION OF async_pt FOR VALUES FROM (3000) TO (4
1156911590
SERVER loopback2 OPTIONS (table_name 'base_tbl3');
1157011591
INSERT INTO async_p3 SELECT 3000 + i, i, to_char(i, 'FM0000') FROM generate_series(0, 999, 5) i;
1157111592
ANALYZE async_pt;
11593+
INFO: Found no remote statistics for "async_p1"
11594+
INFO: Found no remote statistics for "async_p2"
11595+
INFO: Found no remote statistics for "async_p3"
1157211596
EXPLAIN (VERBOSE, COSTS OFF)
1157311597
INSERT INTO result_tbl SELECT * FROM async_pt WHERE b === 505;
1157411598
QUERY PLAN
@@ -11610,6 +11634,8 @@ DROP TABLE base_tbl3;
1161011634
CREATE TABLE async_p3 PARTITION OF async_pt FOR VALUES FROM (3000) TO (4000);
1161111635
INSERT INTO async_p3 SELECT 3000 + i, i, to_char(i, 'FM0000') FROM generate_series(0, 999, 5) i;
1161211636
ANALYZE async_pt;
11637+
INFO: Found no remote statistics for "async_p1"
11638+
INFO: Found no remote statistics for "async_p2"
1161311639
EXPLAIN (VERBOSE, COSTS OFF)
1161411640
INSERT INTO result_tbl SELECT * FROM async_pt WHERE b === 505;
1161511641
QUERY PLAN
@@ -12665,6 +12691,42 @@ ANALYZE analyze_ftable;
1266512691
DROP FOREIGN TABLE analyze_ftable;
1266612692
DROP TABLE analyze_table;
1266712693
-- ===================================================================
12694+
-- test remote analyze
12695+
-- ===================================================================
12696+
CREATE TABLE remote_analyze_table (id int, a text, b bigint);
12697+
INSERT INTO remote_analyze_table (SELECT x FROM generate_series(1,1000) x);
12698+
CREATE FOREIGN TABLE remote_analyze_ftable (id int, a text, b bigint)
12699+
SERVER loopback
12700+
OPTIONS (table_name 'remote_analyze_table', remote_analyze 'true');
12701+
-- no stats before
12702+
SELECT s.tablename, COUNT(*) AS num_stats
12703+
FROM pg_stats AS s
12704+
WHERE s.schemaname = 'public'
12705+
AND s.tablename IN ('remote_analyze_table', 'remote_analyze_ftable')
12706+
GROUP BY s.tablename
12707+
ORDER BY s.tablename;
12708+
tablename | num_stats
12709+
-----------+-----------
12710+
(0 rows)
12711+
12712+
ANALYZE remote_analyze_ftable;
12713+
-- both stats after
12714+
SELECT s.tablename, COUNT(*) AS num_stats
12715+
FROM pg_stats AS s
12716+
WHERE s.schemaname = 'public'
12717+
AND s.tablename IN ('remote_analyze_table', 'remote_analyze_ftable')
12718+
GROUP BY s.tablename
12719+
ORDER BY s.tablename;
12720+
tablename | num_stats
12721+
-----------------------+-----------
12722+
remote_analyze_ftable | 3
12723+
remote_analyze_table | 3
12724+
(2 rows)
12725+
12726+
-- cleanup
12727+
DROP FOREIGN TABLE remote_analyze_ftable;
12728+
DROP TABLE remote_analyze_table;
12729+
-- ===================================================================
1266812730
-- test for postgres_fdw_get_connections function with check_conn = true
1266912731
-- ===================================================================
1267012732
-- Disable debug_discard_caches in order to manage remote connections

contrib/postgres_fdw/option.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
120120
strcmp(def->defname, "async_capable") == 0 ||
121121
strcmp(def->defname, "parallel_commit") == 0 ||
122122
strcmp(def->defname, "parallel_abort") == 0 ||
123+
strcmp(def->defname, "fetch_stats") == 0 ||
124+
strcmp(def->defname, "remote_analyze") == 0 ||
123125
strcmp(def->defname, "keep_connections") == 0)
124126
{
125127
/* these accept only boolean values */
@@ -278,6 +280,14 @@ InitPgFdwOptions(void)
278280
{"use_scram_passthrough", ForeignServerRelationId, false},
279281
{"use_scram_passthrough", UserMappingRelationId, false},
280282

283+
/* fetch_size is available on both server and table */
284+
{"fetch_stats", ForeignServerRelationId, false},
285+
{"fetch_stats", ForeignTableRelationId, false},
286+
287+
/* remote_analyze is available on both server and table */
288+
{"remote_analyze", ForeignServerRelationId, false},
289+
{"remote_analyze", ForeignTableRelationId, false},
290+
281291
/*
282292
* sslcert and sslkey are in fact libpq options, but we repeat them
283293
* here to allow them to appear in both foreign server context (when

0 commit comments

Comments
 (0)