diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2013-02-22 10:56:06 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2013-02-22 10:56:36 -0500 |
commit | c0c6acdfa055b0c76ea0d1defd4c2c0d5a5c256f (patch) | |
tree | 15fa0aeeb52be2d508ce2dfda25a6963924882cf /contrib/postgres_fdw/deparse.c | |
parent | af0a4c5924061869ee3db391900ab745107c966f (diff) |
Fix some planning oversights in postgres_fdw.
Include eval costs of local conditions in remote-estimate mode, and don't
assume the remote eval cost is zero in local-estimate mode. (The best
we can do with that at the moment is to assume a seqscan, which may well
be wildly pessimistic ... but zero won't do at all.)
To get a reasonable local estimate, we need to know the relpages count
for the remote rel, so improve the ANALYZE code to fetch that rather
than just setting the foreign table's relpages field to zero.
Diffstat (limited to 'contrib/postgres_fdw/deparse.c')
-rw-r--r-- | contrib/postgres_fdw/deparse.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/contrib/postgres_fdw/deparse.c b/contrib/postgres_fdw/deparse.c index 0293115054f..9816f550ca5 100644 --- a/contrib/postgres_fdw/deparse.c +++ b/contrib/postgres_fdw/deparse.c @@ -457,6 +457,29 @@ appendWhereClause(StringInfo buf, } /* + * Construct SELECT statement to acquire size in blocks of given relation. + * + * Note: we use local definition of block size, not remote definition. + * This is perhaps debatable. + * + * Note: pg_relation_size() exists in 8.1 and later. + */ +void +deparseAnalyzeSizeSql(StringInfo buf, Relation rel) +{ + Oid relid = RelationGetRelid(rel); + StringInfoData relname; + + /* We'll need the remote relation name as a literal. */ + initStringInfo(&relname); + deparseRelation(&relname, relid); + + appendStringInfo(buf, "SELECT pg_catalog.pg_relation_size("); + deparseStringLiteral(buf, relname.data); + appendStringInfo(buf, "::pg_catalog.regclass) / %d", BLCKSZ); +} + +/* * Construct SELECT statement to acquire sample rows of given relation. * * Note: command is appended to whatever might be in buf already. |