Skip to content
Snippets Groups Projects
  1. Feb 06, 2017
  2. Jan 27, 2017
  3. Jan 25, 2017
  4. Jan 21, 2017
  5. Jan 19, 2017
  6. Jan 06, 2017
    • Tom Lane's avatar
      Invalidate cached plans on FDW option changes. · c52d37c8
      Tom Lane authored
      This fixes problems where a plan must change but fails to do so,
      as seen in a bug report from Rajkumar Raghuwanshi.
      
      For ALTER FOREIGN TABLE OPTIONS, do this through the standard method of
      forcing a relcache flush on the table.  For ALTER FOREIGN DATA WRAPPER
      and ALTER SERVER, just flush the whole plan cache on any change in
      pg_foreign_data_wrapper or pg_foreign_server.  That matches the way
      we handle some other low-probability cases such as opclass changes, and
      it's unclear that the case arises often enough to be worth working harder.
      Besides, that gives a patch that is simple enough to back-patch with
      confidence.
      
      Back-patch to 9.3.  In principle we could apply the code change to 9.2 as
      well, but (a) we lack postgres_fdw to test it with, (b) it's doubtful that
      anyone is doing anything exciting enough with FDWs that far back to need
      this desperately, and (c) the patch doesn't apply cleanly.
      
      Patch originally by Amit Langote, reviewed by Etsuro Fujita and Ashutosh
      Bapat, who each contributed substantial changes as well.
      
      Discussion: https://postgr.es/m/CAKcux6m5cA6rRPTKkqVdJ-R=KKDfe35Q_ZuUqxDSV_4hwga=og@mail.gmail.com
      c52d37c8
  7. Jan 03, 2017
  8. Dec 22, 2016
  9. Nov 04, 2016
  10. Nov 03, 2016
  11. Nov 02, 2016
    • Tom Lane's avatar
      Don't convert Consts into Vars during setrefs.c processing. · da8f3ebf
      Tom Lane authored
      While converting expressions in an upper-level plan node so that they
      reference Vars and expressions provided by the input plan node(s),
      don't convert plain Const items, even if there happens to be a matching
      Const in the input.  It's silly to do so because a Var is more expensive to
      execute than a Const.  Moreover, converting can fool ExecCheckPlanOutput's
      check that an insert or update query inserts nulls into dropped columns,
      leading to "query provides a value for a dropped column" errors during
      INSERT or UPDATE on a table with a dropped column.  We could solve this
      by making that check more complicated, but I don't see the point; this fix
      should save a marginal number of cycles, and it also makes for less messy
      EXPLAIN output, as shown by the ensuing regression test result changes.
      
      Per report from Pavel Hanák.  I have not incorporated a test case based
      on that example, as there doesn't seem to be a simple way of checking
      this in isolation without making a bunch of assumptions about other
      planner and SQL-function behavior.
      
      Back-patch to 9.6.  This setrefs.c behavior exists much further back,
      but there is not currently reason to think that it causes problems
      before 9.6.
      
      Discussion: <83shraampf.fsf@is-it.eu>
      da8f3ebf
  12. Nov 01, 2016
  13. Oct 26, 2016
  14. Oct 25, 2016
  15. Oct 21, 2016
    • Robert Haas's avatar
      postgres_fdw: Attempt to stabilize regression results. · ad13a09d
      Robert Haas authored
      Set enable_hashagg to false for tests involving least_agg(), so that
      we get the same plan regardless of local costing variances.  Also,
      remove a test involving sqrt(); it's there to test deparsing of
      HAVING clauses containing expressions, but that's tested elsewhere
      anyway, and sqrt(2) deparses with different amounts of precision on
      different machines.
      
      Per buildfarm.
      ad13a09d
    • Robert Haas's avatar
      postgres_fdw: Push down aggregates to remote servers. · 7012b132
      Robert Haas authored
      Now that the upper planner uses paths, and now that we have proper hooks
      to inject paths into the upper planning process, it's possible for
      foreign data wrappers to arrange to push aggregates to the remote side
      instead of fetching all of the rows and aggregating them locally.  This
      figures to be a massive win for performance, so teach postgres_fdw to
      do it.
      
      Jeevan Chalke and Ashutosh Bapat.  Reviewed by Ashutosh Bapat with
      additional testing by Prabhat Sahu.  Various mostly cosmetic changes
      by me.
      7012b132
  16. Oct 05, 2016
    • Robert Haas's avatar
      Rename WAIT_* constants to PG_WAIT_*. · d2ce38e2
      Robert Haas authored
      Windows apparently has a constant named WAIT_TIMEOUT, and some of these
      other names are pretty generic, too.  Insert "PG_" at the front of each
      name in order to disambiguate.
      
      Michael Paquier
      d2ce38e2
  17. Oct 04, 2016
    • Robert Haas's avatar
      Extend framework from commit 53be0b1a to report latch waits. · 6f3bd98e
      Robert Haas authored
      WaitLatch, WaitLatchOrSocket, and WaitEventSetWait now taken an
      additional wait_event_info parameter; legal values are defined in
      pgstat.h.  This makes it possible to uniquely identify every point in
      the core code where we are waiting for a latch; extensions can pass
      WAIT_EXTENSION.
      
      Because latches were the major wait primitive not previously covered
      by this patch, it is now possible to see information in
      pg_stat_activity on a large number of important wait events not
      previously addressed, such as ClientRead, ClientWrite, and SyncRep.
      
      Unfortunately, many of the wait events added by this patch will fail
      to appear in pg_stat_activity because they're only used in background
      processes which don't currently appear in pg_stat_activity.  We should
      fix this either by creating a separate view for such information, or
      else by deciding to include them in pg_stat_activity after all.
      
      Michael Paquier and Robert Haas, reviewed by Alexander Korotkov and
      Thomas Munro.
      6f3bd98e
  18. Aug 27, 2016
    • Tom Lane's avatar
      Add macros to make AllocSetContextCreate() calls simpler and safer. · ea268cdc
      Tom Lane authored
      I found that half a dozen (nearly 5%) of our AllocSetContextCreate calls
      had typos in the context-sizing parameters.  While none of these led to
      especially significant problems, they did create minor inefficiencies,
      and it's now clear that expecting people to copy-and-paste those calls
      accurately is not a great idea.  Let's reduce the risk of future errors
      by introducing single macros that encapsulate the common use-cases.
      Three such macros are enough to cover all but two special-purpose contexts;
      those two calls can be left as-is, I think.
      
      While this patch doesn't in itself improve matters for third-party
      extensions, it doesn't break anything for them either, and they can
      gradually adopt the simplified notation over time.
      
      In passing, change TopMemoryContext to use the default allocation
      parameters.  Formerly it could only be extended 8K at a time.  That was
      probably reasonable when this code was written; but nowadays we create
      many more contexts than we did then, so that it's not unusual to have a
      couple hundred K in TopMemoryContext, even without considering various
      dubious code that sticks other things there.  There seems no good reason
      not to let it use growing blocks like most other contexts.
      
      Back-patch to 9.6, mostly because that's still close enough to HEAD that
      it's easy to do so, and keeping the branches in sync can be expected to
      avoid some future back-patching pain.  The bugs fixed by these changes
      don't seem to be significant enough to justify fixing them further back.
      
      Discussion: <21072.1472321324@sss.pgh.pa.us>
      ea268cdc
  19. Aug 26, 2016
    • Heikki Linnakangas's avatar
      Support OID system column in postgres_fdw. · ae025a15
      Heikki Linnakangas authored
      You can use ALTER FOREIGN TABLE SET WITH OIDS on a foreign table, but the
      oid column read out as zeros, because the postgres_fdw didn't know about
      it. Teach postgres_fdw how to fetch it.
      
      Etsuro Fujita, with an additional test case by me.
      
      Discussion: <56E90A76.5000503@lab.ntt.co.jp>
      ae025a15
  20. Aug 24, 2016
  21. Jul 28, 2016
    • Tom Lane's avatar
      Fix assorted fallout from IS [NOT] NULL patch. · 9492cf86
      Tom Lane authored
      Commits 4452000f et al established semantics for NullTest.argisrow that
      are a bit different from its initial conception: rather than being merely
      a cache of whether we've determined the input to have composite type,
      the flag now has the further meaning that we should apply field-by-field
      testing as per the standard's definition of IS [NOT] NULL.  If argisrow
      is false and yet the input has composite type, the construct instead has
      the semantics of IS [NOT] DISTINCT FROM NULL.  Update the comments in
      primnodes.h to clarify this, and fix ruleutils.c and deparse.c to print
      such cases correctly.  In the case of ruleutils.c, this merely results in
      cosmetic changes in EXPLAIN output, since the case can't currently arise
      in stored rules.  However, it represents a live bug for deparse.c, which
      would formerly have sent a remote query that had semantics different
      from the local behavior.  (From the user's standpoint, this means that
      testing a remote nested-composite column for null-ness could have had
      unexpected recursive behavior much like that fixed in 4452000f.)
      
      In a related but somewhat independent fix, make plancat.c set argisrow
      to false in all NullTest expressions constructed to represent "attnotnull"
      constructs.  Since attnotnull is actually enforced as a simple null-value
      check, this is a more accurate representation of the semantics; we were
      previously overpromising what it meant for composite columns, which might
      possibly lead to incorrect planner optimizations.  (It seems that what the
      SQL spec expects a NOT NULL constraint to mean is an IS NOT NULL test, so
      arguably we are violating the spec and should fix attnotnull to do the
      other thing.  If we ever do, this part should get reverted.)
      
      Back-patch, same as the previous commit.
      
      Discussion: <10682.1469566308@sss.pgh.pa.us>
      9492cf86
  22. Jul 25, 2016
  23. Jul 15, 2016
    • Tom Lane's avatar
      Avoid invalidating all foreign-join cached plans when user mappings change. · 45639a05
      Tom Lane authored
      We must not push down a foreign join when the foreign tables involved
      should be accessed under different user mappings.  Previously we tried
      to enforce that rule literally during planning, but that meant that the
      resulting plans were dependent on the current contents of the
      pg_user_mapping catalog, and we had to blow away all cached plans
      containing any remote join when anything at all changed in pg_user_mapping.
      This could have been improved somewhat, but the fact that a syscache inval
      callback has very limited info about what changed made it hard to do better
      within that design.  Instead, let's change the planner to not consider user
      mappings per se, but to allow a foreign join if both RTEs have the same
      checkAsUser value.  If they do, then they necessarily will use the same
      user mapping at runtime, and we don't need to know specifically which one
      that is.  Post-plan-time changes in pg_user_mapping no longer require any
      plan invalidation.
      
      This rule does give up some optimization ability, to wit where two foreign
      table references come from views with different owners or one's from a view
      and one's directly in the query, but nonetheless the same user mapping
      would have applied.  We'll sacrifice the first case, but to not regress
      more than we have to in the second case, allow a foreign join involving
      both zero and nonzero checkAsUser values if the nonzero one is the same as
      the prevailing effective userID.  In that case, mark the plan as only
      runnable by that userID.
      
      The plancache code already had a notion of plans being userID-specific,
      in order to support RLS.  It was a little confused though, in particular
      lacking clarity of thought as to whether it was the rewritten query or just
      the finished plan that's dependent on the userID.  Rearrange that code so
      that it's clearer what depends on which, and so that the same logic applies
      to both RLS-injected role dependency and foreign-join-injected role
      dependency.
      
      Note that this patch doesn't remove the other issue mentioned in the
      original complaint, which is that while we'll reliably stop using a foreign
      join if it's disallowed in a new context, we might fail to start using a
      foreign join if it's now allowed, but we previously created a generic
      cached plan that didn't use one.  It was agreed that the chance of winning
      that way was not high enough to justify the much larger number of plan
      invalidations that would have to occur if we tried to cause it to happen.
      
      In passing, clean up randomly-varying spelling of EXPLAIN commands in
      postgres_fdw.sql, and fix a COSTS ON example that had been allowed to
      leak into the committed tests.
      
      This reverts most of commits fbe5a3fb and 5d4171d1, which were the
      previous attempt at ensuring we wouldn't push down foreign joins that
      span permissions contexts.
      
      Etsuro Fujita and Tom Lane
      
      Discussion: <d49c1e5b-f059-20f4-c132-e9752ee0113e@lab.ntt.co.jp>
      45639a05
  24. Jul 01, 2016
  25. Jun 24, 2016
  26. Jun 17, 2016
    • Robert Haas's avatar
      postgres_fdw: Rephrase comment. · 177c56d6
      Robert Haas authored
      Per gripe from Thomas Munro, who only complained about a more
      localized problem, but I couldn't resist a bit more wordsmithing.
      177c56d6
  27. Jun 14, 2016
    • Robert Haas's avatar
      postgres_fdw: Check PlaceHolderVars before pushing down a join. · 131c7e70
      Robert Haas authored
      As discovered by Andreas Seltenreich via sqlsmith, it's possible for a
      remote join to need to generate a target list which contains a
      PlaceHolderVar which would need to be evaluated on the remote server.
      This happens when we try to push down a join tree which contains outer
      joins and the nullable side of the join contains a subquery which
      evauates some expression which can go to NULL above the level of the
      join.  Since the deparsing logic can't build a remote query that
      involves subqueries, it fails while trying to produce an SQL query
      that can be sent to the remote side.  Detect such cases and don't try
      to push down the join at all.
      
      It's actually fine to push down the join if the PlaceHolderVar needs
      to be evaluated at the current join level.  This patch makes a small
      change to build_tlist_to_deparse so that this case will work.
      
      Amit Langote, Ashutosh Bapat, and me.
      131c7e70
    • Robert Haas's avatar
      postgres_fdw: Promote an Assert() to elog(). · 332fdbef
      Robert Haas authored
      Andreas Seltenreich reports that it is possible for a PlaceHolderVar
      to creep into this tlist, and I fear that even after that's fixed we
      might have other, similar bugs in this area either now or in the
      future.  There's a lot of action-at-a-distance here, because the
      validity of this assertion depends on core planner behavior; so, let's
      use elog() to make sure we catch this even in non-assert builds,
      rather than just crashing.
      332fdbef
  28. Jun 10, 2016
  29. May 16, 2016
    • Robert Haas's avatar
      postgres_fdw: Fix the fix for crash when pushing down multiple joins. · 02a568a0
      Robert Haas authored
      Commit 3151f16e was intended to be
      a commit of a patch from Ashutosh Bapat, but instead I mistakenly
      committed an earlier version from Michael Paquier (because both
      patches were submitted with the same filename, and I confused them).
      Michael's patch fixes the crash but doesn't actually implement the
      correct test.
      
      Repair the incorrect logic, and also expand the comments considerably
      so that this is all more clear.
      
      Ashutosh Bapat and Robert Haas
      02a568a0
    • Robert Haas's avatar
      Fix multiple problems in postgres_fdw query cancellation logic. · 1b812afb
      Robert Haas authored
      First, even if we cancel a query, we still have to roll back the
      containing transaction; otherwise, the session will be left in a
      failed transaction state.
      
      Second, we need to support canceling queries whe aborting a
      subtransaction as well as when aborting a toplevel transaction.
      
      Etsuro Fujita, reviewed by Michael Paquier
      1b812afb
  30. Apr 21, 2016
    • Robert Haas's avatar
      Allow queries submitted by postgres_fdw to be canceled. · f039eaac
      Robert Haas authored
      This fixes a problem which is not new, but with the advent of direct
      foreign table modification in 0bf3ae88,
      it's somewhat more likely to be annoying than previously.  So,
      arrange for a local query cancelation to propagate to the remote side.
      
      Michael Paquier, reviewed by Etsuro Fujita.	 Original report by
      Thom Brown.
      f039eaac
    • Robert Haas's avatar
      postgres_fdw: Don't push down certain full joins. · 5b1f9ce1
      Robert Haas authored
      If there's a filter condition on either side of a full outer join,
      it is neither correct to attach it to the join's ON clause nor to
      throw it into the toplevel WHERE clause.  Just don't push down the
      join in that case.
      
      To maximize the number of cases where we can still push down full
      joins, push inner join conditions into the ON clause at the first
      opportunity rather than postponing them to the top-level WHERE
      clause.  This produces nicer SQL, anyway.
      
      This bug was introduced in e4106b25.
      
      Ashutosh Bapat, per report from Rajkumar Raghuwanshi.
      5b1f9ce1
  31. Apr 15, 2016
    • Robert Haas's avatar
      postgres_fdw: Clean up handling of system columns. · da7d44b6
      Robert Haas authored
      Previously, querying the xmin column of a single postgres_fdw foreign
      table fetched the tuple length, xmax the typmod, and cmin or cmax the
      composite type OID of the tuple.  However, when you queried several
      such tables and the join got shipped to the remote side, these columns
      ended up containing the remote values of the corresponding columns.
      Both behaviors are rather unprincipled, the former for obvious reasons
      and the latter because the remote values of these columns don't have
      any local significance; our transaction IDs are in a different space
      than those of the remote machine.  Clean this up by setting all of
      these fields to 0 in both cases.  Also fix the handling of tableoid
      to be sane.
      
      Robert Haas and Ashutosh Bapat, reviewed by Etsuro Fujita.
      da7d44b6
  32. Apr 06, 2016
Loading