Skip to content
Snippets Groups Projects
  1. 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
  2. Jun 10, 2016
  3. 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
  4. 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
  5. 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
  6. Apr 06, 2016
  7. Mar 29, 2016
  8. Mar 23, 2016
    • Robert Haas's avatar
      postgres_fdw: Fix crash when pushing down multiple joins. · 3151f16e
      Robert Haas authored
      A join clause might mention multiple relations on either side, so it
      need not be the case that a given joinrel's constituent relations are
      all on one side of the join clause or all on the other.
      
      Report by Rajkumar Raghuwanshi.  Analysis and fix by Michael Paquier
      and Ashutosh Bapat.
      3151f16e
  9. Mar 21, 2016
    • Tom Lane's avatar
      Clean up some Coverity complaints about commit 0bf3ae88. · 92b7902d
      Tom Lane authored
      The two get_tle_by_resno() calls introduced by this commit lacked any
      check for a NULL return, unlike any other calls of that function anywhere
      in our tree.  Coverity quite properly complained about it.  Also fix a
      misindented line in process_query_params(), which Coverity also complained
      about on the grounds that the bad indentation suggested possible programmer
      misinterpretation.
      92b7902d
  10. Mar 18, 2016
    • Robert Haas's avatar
      Directly modify foreign tables. · 0bf3ae88
      Robert Haas authored
      postgres_fdw can now sent an UPDATE or DELETE statement directly to
      the foreign server in simple cases, rather than sending a SELECT FOR
      UPDATE statement and then updating or deleting rows one-by-one.
      
      Etsuro Fujita, reviewed by Rushabh Lathia, Shigeru Hanada, Kyotaro
      Horiguchi, Albe Laurenz, Thom Brown, and me.
      0bf3ae88
  11. Mar 15, 2016
  12. Mar 14, 2016
    • Tom Lane's avatar
      Allow callers of create_foreignscan_path to specify nondefault PathTarget. · 28048cba
      Tom Lane authored
      Although the default choice of rel->reltarget should typically be
      sufficient for scan or join paths, it's not at all sufficient for the
      purposes PathTargets were invented for; in particular not for
      upper-relation Paths.  So break API compatibility by adding a PathTarget
      argument to create_foreignscan_path().  To ease updating of existing
      code, accept a NULL value of the argument as selecting rel->reltarget.
      28048cba
    • Tom Lane's avatar
      Rethink representation of PathTargets. · 307c7885
      Tom Lane authored
      In commit 19a54114 I did not make PathTarget a subtype of Node,
      and embedded a RelOptInfo's reltarget directly into it rather than having
      a separately-allocated Node.  In hindsight that was misguided
      micro-optimization, enabled by the fact that at that point we didn't have
      any Paths with custom PathTargets.  Now that PathTarget processing has
      been fleshed out some more, it's easier to see that it's better to have
      PathTarget as an indepedent Node type, even if it does cost us one more
      palloc to create a RelOptInfo.  So change it while we still can.
      
      This commit just changes the representation, without doing anything more
      interesting than that.
      307c7885
    • Robert Haas's avatar
      Update more comments for 96198d94. · 6be84eeb
      Robert Haas authored
      Etsuro Fujita, reviewed (though not completely endorsed) by Ashutosh
      Bapat, and slightly expanded by me.
      6be84eeb
  13. Mar 10, 2016
    • Tom Lane's avatar
      Refactor pull_var_clause's API to make it less tedious to extend. · 364a9f47
      Tom Lane authored
      In commit 1d97c19a and later c1d9579d, we extended
      pull_var_clause's API by adding enum-type arguments.  That's sort of a pain
      to maintain, though, because it means every time we add a new behavior we
      must touch every last one of the call sites, even if there's a reasonable
      default behavior that most of them could use.  Let's switch over to using a
      bitmask of flags, instead; that seems more maintainable and might save a
      nanosecond or two as well.  This commit changes no behavior in itself,
      though I'm going to follow it up with one that does add a new behavior.
      
      In passing, remove flatten_tlist(), which has not been used since 9.1
      and would otherwise need the same API changes.
      
      Removing these enums means that optimizer/tlist.h no longer needs to
      depend on optimizer/var.h.  Changing that caused a number of C files to
      need addition of #include "optimizer/var.h" (probably we can thank old
      runs of pgrminclude for that); but on balance it seems like a good change
      anyway.
      364a9f47
  14. Mar 09, 2016
    • Robert Haas's avatar
      postgres_fdw: Consider foreign joining and foreign sorting together. · aa09cd24
      Robert Haas authored
      Commit ccd8f979 gave us the ability to
      request that the remote side sort the data, and, later, commit
      e4106b25 gave us the ability to
      request that the remote side perform the join for us rather than doing
      it locally.  But we could not do both things at the same time: a
      remote SQL query that had an ORDER BY clause would never be a join.
      This commit adds that capability.
      
      Ashutosh Bapat, reviewed by me.
      aa09cd24
  15. Mar 08, 2016
  16. Mar 04, 2016
    • Robert Haas's avatar
      postgres_fdw: When sending ORDER BY, always include NULLS FIRST/LAST. · 3bea3f88
      Robert Haas authored
      Previously, we included NULLS FIRST when appropriate but relied on the
      default behavior to be NULLS LAST.  This is, however, not true for a
      sort in descending order and seems like a fragile assumption anyway.
      
      Report by Rajkumar Raghuwanshi.  Patch by Ashutosh Bapat.  Review
      comments from Michael Paquier and Tom Lane.
      3bea3f88
  17. Feb 21, 2016
    • Robert Haas's avatar
      postgres_fdw: Avoid sharing list substructure. · dd077ef8
      Robert Haas authored
      list_concat(list_concat(a, b), c) destructively changes both a and b;
      to avoid such perils, copy lists of remote_conds before incorporating
      them into larger lists via list_concat().
      
      Ashutosh Bapat, per a report from Etsuro Fujita
      dd077ef8
  18. Feb 19, 2016
    • Tom Lane's avatar
      Add an explicit representation of the output targetlist to Paths. · 19a54114
      Tom Lane authored
      Up to now, there's been an assumption that all Paths for a given relation
      compute the same output column set (targetlist).  However, there are good
      reasons to remove that assumption.  For example, an indexscan on an
      expression index might be able to return the value of an expensive function
      "for free".  While we have the ability to generate such a plan today in
      simple cases, we don't have a way to model that it's cheaper than a plan
      that computes the function from scratch, nor a way to create such a plan
      in join cases (where the function computation would normally happen at
      the topmost join node).  Also, we need this so that we can have Paths
      representing post-scan/join steps, where the targetlist may well change
      from one step to the next.  Therefore, invent a "struct PathTarget"
      representing the columns we expect a plan step to emit.  It's convenient
      to include the output tuple width and tlist evaluation cost in this struct,
      and there will likely be additional fields in future.
      
      While Path nodes that actually do have custom outputs will need their own
      PathTargets, it will still be true that most Paths for a given relation
      will compute the same tlist.  To reduce the overhead added by this patch,
      keep a "default PathTarget" in RelOptInfo, and allow Paths that compute
      that column set to just point to their parent RelOptInfo's reltarget.
      (In the patch as committed, actually every Path is like that, since we
      do not yet have any cases of custom PathTargets.)
      
      I took this opportunity to provide some more-honest costing of
      PlaceHolderVar evaluation.  Up to now, the assumption that "scan/join
      reltargetlists have cost zero" was applied not only to Vars, where it's
      reasonable, but also PlaceHolderVars where it isn't.  Now, we add the eval
      cost of a PlaceHolderVar's expression to the first plan level where it can
      be computed, by including it in the PathTarget cost field and adding that
      to the cost estimates for Paths.  This isn't perfect yet but it's much
      better than before, and there is a way forward to improve it more.  This
      costing change affects the join order chosen for a couple of the regression
      tests, changing expected row ordering.
      19a54114
  19. Feb 12, 2016
  20. Feb 10, 2016
  21. Feb 09, 2016
    • Robert Haas's avatar
      postgres_fdw: Remove unstable regression test. · bb4df42e
      Robert Haas authored
      Per Tom Lane and the buildfarm.
      bb4df42e
    • Robert Haas's avatar
      postgres_fdw: Push down joins to remote servers. · e4106b25
      Robert Haas authored
      If we've got a relatively straightforward join between two tables,
      this pushes that join down to the remote server instead of fetching
      the rows for each table and performing the join locally.  Some cases
      are not handled yet, such as SEMI and ANTI joins.  Also, we don't
      yet attempt to create presorted join paths or parameterized join
      paths even though these options do get tried for a base relation
      scan.  Nevertheless, this seems likely to be a very significant win
      in many practical cases.
      
      Shigeru Hanada and Ashutosh Bapat, reviewed by Robert Haas, with
      additional review at various points by Tom Lane, Etsuro Fujita,
      KaiGai Kohei, and Jeevan Chalke.
      e4106b25
  22. Feb 08, 2016
  23. Feb 06, 2016
  24. Feb 05, 2016
  25. Feb 03, 2016
    • Robert Haas's avatar
      Code review for commit dc203dc3. · 52b63649
      Robert Haas authored
      Remove duplicate assignment.  This part by Ashutosh Bapat.
      
      Remove now-obsolete comment.  This part by me, although the pending
      join pushdown patch does something similar, and for the same reason:
      there's no reason to keep two lists of the things in the fdw_private
      structure that have to be kept in sync with each other.
      52b63649
    • Robert Haas's avatar
      postgres_fdw: Allow fetch_size to be set per-table or per-server. · dc203dc3
      Robert Haas authored
      The default fetch size of 100 rows might not be right in every
      environment, so allow users to configure it.
      
      Corey Huinker, reviewed by Kyotaro Horiguchi, Andres Freund, and me.
      dc203dc3
  26. Jan 30, 2016
    • Robert Haas's avatar
      postgres_fdw: More preliminary refactoring for upcoming join pushdown. · cc592c48
      Robert Haas authored
      The code that generates a complete SQL query for a given foreign relation
      was repeated in two places, and they didn't quite agree: the EXPLAIN case
      left out the locking clause.  Centralize the code so we get the same
      behavior everywhere, and adjust calling conventions and which functions
      are static vs. extern accordingly .  Centralize the code so we get the same
      behavior everywhere, and adjust calling conventions and which functions
      are static vs. extern accordingly.
      
      Ashutosh Bapat, reviewed and slightly adjusted by me.
      cc592c48
  27. Jan 29, 2016
    • Tom Lane's avatar
      Fix incorrect pattern-match processing in psql's \det command. · 7e224704
      Tom Lane authored
      listForeignTables' invocation of processSQLNamePattern did not match up
      with the other ones that handle potentially-schema-qualified names; it
      failed to make use of pg_table_is_visible() and also passed the name
      arguments in the wrong order.  Bug seems to have been aboriginal in commit
      0d692a0d.  It accidentally sort of worked as long as you didn't
      inquire too closely into the behavior, although the silliness was later
      exposed by inconsistencies in the test queries added by 59efda3e
      (which I probably should have questioned at the time, but didn't).
      
      Per bug #13899 from Reece Hart.  Patch by Reece Hart and Tom Lane.
      Back-patch to all affected branches.
      7e224704
  28. Jan 28, 2016
    • Robert Haas's avatar
      postgres_fdw: Refactor deparsing code for locking clauses. · b88ef201
      Robert Haas authored
      The upcoming patch to allow join pushdown in postgres_fdw needs to use
      this code multiple times, which requires moving it to deparse.c.  That
      seems like a good idea anyway, so do that now both on general principle
      and to simplify the future patch.
      
      Inspired by a patch by Shigeru Hanada and Ashutosh Bapat, but I did
      it a little differently than what that patch did.
      b88ef201
    • Robert Haas's avatar
      Add missing quotation mark. · 2f6b041f
      Robert Haas authored
      This fix accidentally got left out of the previous commit.
      2f6b041f
    • Robert Haas's avatar
      Avoid multiple foreign server connections when all use same user mapping. · 96198d94
      Robert Haas authored
      Previously, postgres_fdw's connection cache was keyed by user OID and
      server OID, but this can lead to multiple connections when it's not
      really necessary.  In particular, if all relevant users are mapped to
      the public user mapping, then their connection options are certainly
      the same, so one connection can be used for all of them.
      
      While we're cleaning things up here, drop the "server" argument to
      GetConnection(), which isn't really needed.  This saves a few cycles
      because callers no longer have to look this up; the function itself
      does, but only when establishing a new connection, not when reusing
      an existing one.
      
      Ashutosh Bapat, with a few small changes by me.
      96198d94
  29. Jan 02, 2016
  30. Dec 31, 2015
    • Tom Lane's avatar
      Add a comment noting that FDWs don't have to implement EXCEPT or LIMIT TO. · 5f36096b
      Tom Lane authored
      postgresImportForeignSchema pays attention to IMPORT's EXCEPT and LIMIT TO
      options, but only as an efficiency hack, not for correctness' sake.  The
      FDW documentation does explain that, but someone using postgres_fdw.c
      as a coding guide might not remember it, so let's add a comment here.
      Per question from Regina Obe.
      5f36096b
Loading