pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
postgres_fdw pushdown problem.
3+ messages / 2 participants
[nested] [flat]

* postgres_fdw pushdown problem.
@ 2018-11-20 18:03  Rhys A.D. Stewart <rhys.stewart@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Rhys A.D. Stewart @ 2018-11-20 18:03 UTC (permalink / raw)
  To: pgsql-general

Greetings all,

I'm using postgres_fdw and am having a pushdown issue. The TL;DR is
that the where clause doesn't get pushed down for the last of the
following three queries.

SELECT * FROM service.mrrdr_synth WHERE premises = '1057430';
SELECT * FROM service.mrrdr_synth WHERE reading_val = '8';
SELECT * FROM service.mrrdr_synth WHERE location_capture_time =
'2018-10-20 12:02:53.097247-05'::timestamptz;

The documentation that I have read doesn't indicate why this would be
the case. So looking to figure out why this is happening.

The following obtains:

Local server version: PostgreSQL 10.4, compiled by Visual C++ build 1800, 64-bit

foreign table DDL:

CREATE FOREIGN TABLE service.mrrdr_synth(
    premises text NULL COLLATE pg_catalog."default",
    meter_num text NULL COLLATE pg_catalog."default",
    routeid text NULL COLLATE pg_catalog."default",
    lineinfo text NULL COLLATE pg_catalog."default",
    reading_val text NULL COLLATE pg_catalog."default",
    location_capture_time timestamp without time zone NULL,
    g geometry NULL
)
    SERVER "ldceng006-pc"
    OPTIONS (schema_name 'mrrdr', table_name 'synth');

Foreign server version: PostgreSQL 10.1, compiled by Visual C++ build
1800, 64-bit.

CREATE MATERIALIZED VIEW mrrdr.synth
AS
 SELECT cr.premises,
    mr.meter_num,
    cr.routeid,
    cr.lineinfo,
    responses.reading_val,
    responses.location_capture_time,
    responses.g
   FROM mrrdr.customer_record cr
     JOIN mrrdr.meter_record mr USING (premises, routeid)
     JOIN mrrdr.responses USING (meter_num, routeid)
  WHERE cr.routeid::text >= '20160701001021'::text
WITH DATA;

CREATE INDEX synth_g_idx
    ON mrrdr.synth USING gist
    (g);
CREATE INDEX synth_premises_idx
    ON mrrdr.synth USING btree
    (premises COLLATE pg_catalog."default");
CREATE INDEX synth_routeid_idx
    ON mrrdr.synth USING btree
    (routeid COLLATE pg_catalog."default");
CREATE INDEX synth_substring_idx
    ON mrrdr.synth USING btree
    ("substring"(routeid::text, 10, 5) COLLATE pg_catalog."default");

The relations in the above query are all materialized views and all
those materialized views pull from foreign tables using ogr_fdw, not
sure if this is pertinent info.

Regards,

Rhys
Peace & Love|Live Long & Prosper




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: postgres_fdw pushdown problem.
@ 2018-11-20 18:23  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Rhys A.D. Stewart <rhys.stewart@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2018-11-20 18:23 UTC (permalink / raw)
  To: Rhys A.D. Stewart <rhys.stewart@gmail.com>; +Cc: pgsql-general

"Rhys A.D. Stewart" <rhys.stewart@gmail.com> writes:
> I'm using postgres_fdw and am having a pushdown issue. The TL;DR is
> that the where clause doesn't get pushed down for the last of the
> following three queries.

> SELECT * FROM service.mrrdr_synth WHERE premises = '1057430';
> SELECT * FROM service.mrrdr_synth WHERE reading_val = '8';
> SELECT * FROM service.mrrdr_synth WHERE location_capture_time =
> '2018-10-20 12:02:53.097247-05'::timestamptz;

Well, you've got

> CREATE FOREIGN TABLE service.mrrdr_synth( ...
>     location_capture_time timestamp without time zone NULL,

so that WHERE clause is a comparison of timestamp vs timestamptz,
which depends on the active timezone setting, so it's not immutable
and won't get pushed.  (In English: the planner is afraid the remote
end might be using a different timezone setting.)  I'm pretty sure
either timestamp = timestamp or timestamptz = timestamptz would be
pushable.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: postgres_fdw pushdown problem.
@ 2018-11-20 18:40  Rhys A.D. Stewart <rhys.stewart@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Rhys A.D. Stewart @ 2018-11-20 18:40 UTC (permalink / raw)
  To: tgl@sss.pgh.pa.us; +Cc: pgsql-general

The devil really is in the details.

> end might be using a different timezone setting.)  I'm pretty sure
> either timestamp = timestamp or timestamptz = timestamptz would be
> pushable.

Yeah, casting to plain old timestamp worked.

Thanks Tom.

Rhys
Peace & Love|Live Long & Prosper




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2018-11-20 18:40 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-11-20 18:03 postgres_fdw pushdown problem. Rhys A.D. Stewart <rhys.stewart@gmail.com>
2018-11-20 18:23 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-11-20 18:40   ` Rhys A.D. Stewart <rhys.stewart@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox