1. 27 Nov, 2015 3 commits
    • Tom Lane's avatar
      Auto-generate file header comments in Unicode mapping files. · e17dab53
      Tom Lane authored
      Some of the Unicode/*.map files had identification comments added to them,
      evidently by hand.  Others did not.  Modify the generating scripts to
      produce these comments automatically, and update the generated files that
      lacked them.
      
      This is just minor cleanup as a by-product of trying to verify that the
      *.map files can indeed be reproduced from authoritative data.  There are a
      depressingly large number that fail to reproduce from the claimed sources.
      I have not touched those in this commit, except for the JIS 2004-related
      files which required only a single comment update to match.
      
      Since this only affects comments, no need to consider a back-patch.
      e17dab53
    • Tom Lane's avatar
      Improve PQhost() to return useful data for default Unix-socket connections. · 40cb21f7
      Tom Lane authored
      Previously, if no host information had been specified at connection time,
      PQhost() would return NULL (unless you are on Windows, in which case you
      got "localhost").  This is an unhelpful definition for a couple of reasons:
      it can cause corner-case crashes in applications (cf commit c5ef8ce5),
      and there's no well-defined way for applications to find out the socket
      directory path that's actually in use.  As an example of the latter
      problem, psql substituted DEFAULT_PGSOCKET_DIR for NULL in a couple of
      places, but this is subtly wrong because it's conceivable that psql is
      using a libpq shared library that was built with a different setting.
      
      Hence, change PQhost() to return DEFAULT_PGSOCKET_DIR when appropriate,
      and strip out the now-dead substitutions in psql.  (There is still one
      remaining reference to DEFAULT_PGSOCKET_DIR in psql, in prompt.c, which
      I don't see a nice way to get rid of.  But it only controls a prompt
      abbreviation decision, so it seems noncritical.)
      
      Also update the docs for PQhost, which had never previously mentioned
      the possibility of a socket directory path being returned.  In passing
      fix the outright-incorrect code comment about PGconn.pgunixsocket.
      40cb21f7
    • Teodor Sigaev's avatar
      COPY (INSERT/UPDATE/DELETE .. RETURNING ..) · 92e38182
      Teodor Sigaev authored
      Attached is a patch for being able to do COPY (query) without a CTE.
      
      Author: Marko Tiikkaja
      Review: Michael Paquier
      92e38182
  2. 26 Nov, 2015 1 commit
    • Tom Lane's avatar
      Fix failure to consider failure cases in GetComboCommandId(). · 0da3a9be
      Tom Lane authored
      Failure to initially palloc the comboCids array, or to realloc it bigger
      when needed, left combocid's data structures in an inconsistent state that
      would cause trouble if the top transaction continues to execute.  Noted
      while examining a user complaint about the amount of memory used for this.
      (There's not much we can do about that, but it does point up that repalloc
      failure has a non-negligible chance of occurring here.)
      
      In HEAD/9.5, also avoid possible invocation of memcpy() with a null pointer
      in SerializeComboCIDState; cf commit 13bba022.
      0da3a9be
  3. 25 Nov, 2015 4 commits
    • Tom Lane's avatar
      Be more paranoid about null return values from libpq status functions. · c5ef8ce5
      Tom Lane authored
      PQhost() can return NULL in non-error situations, namely when a Unix-socket
      connection has been selected by default.  That behavior is a tad debatable
      perhaps, but for the moment we should make sure that psql copes with it.
      Unfortunately, do_connect() failed to: it could pass a NULL pointer to
      strcmp(), resulting in crashes on most platforms.  This was reported as a
      security issue by ChenQin of Topsec Security Team, but the consensus of
      the security list is that it's just a garden-variety bug with no security
      implications.
      
      For paranoia's sake, I made the keep_password test not trust PQuser or
      PQport either, even though I believe those will never return NULL given
      a valid PGconn.
      
      Back-patch to all supported branches.
      c5ef8ce5
    • Tom Lane's avatar
      Improve div_var_fast(), mostly by making comments better. · 46166197
      Tom Lane authored
      The integer overflow situation in div_var_fast() is a great deal more
      complicated than the pre-existing comments would suggest.  Moreover, the
      comments were also flat out incorrect as to the precise statement of the
      maxdiv loop invariant.  Upon clarifying that, it becomes apparent that the
      way in which we updated maxdiv after a carry propagation pass was overly
      slow, complex, and conservative: we can just reset it to one, which is much
      easier and also reduces the number of times carry propagation occurs.
      Fix that and improve the relevant comments.
      
      Since this is mostly a comment fix, with only a rather marginal performance
      boost, no need for back-patch.
      
      Tom Lane and Dean Rasheed
      46166197
    • Teodor Sigaev's avatar
      Add forgotten file in commit d6061f83 · 0271e27c
      Teodor Sigaev authored
      0271e27c
    • Teodor Sigaev's avatar
      Improve pageinspect module · d6061f83
      Teodor Sigaev authored
      Now pageinspect can show data stored in the heap tuple.
      
      Nikolay Shaplov
      d6061f83
  4. 24 Nov, 2015 2 commits
  5. 23 Nov, 2015 2 commits
  6. 22 Nov, 2015 1 commit
    • Tom Lane's avatar
      Adopt the GNU convention for handling tar-archive members exceeding 8GB. · 00cdd835
      Tom Lane authored
      The POSIX standard for tar headers requires archive member sizes to be
      printed in octal with at most 11 digits, limiting the representable file
      size to 8GB.  However, GNU tar and apparently most other modern tars
      support a convention in which oversized values can be stored in base-256,
      allowing any practical file to be a tar member.  Adopt this convention
      to remove two limitations:
      * pg_dump with -Ft output format failed if the contents of any one table
      exceeded 8GB.
      * pg_basebackup failed if the data directory contained any file exceeding
      8GB.  (This would be a fatal problem for installations configured with a
      table segment size of 8GB or more, and it has also been seen to fail when
      large core dump files exist in the data directory.)
      
      File sizes under 8GB are still printed in octal, so that no compatibility
      issues are created except in cases that would have failed entirely before.
      
      In addition, this patch fixes several bugs in the same area:
      
      * In 9.3 and later, we'd defined tarCreateHeader's file-size argument as
      size_t, which meant that on 32-bit machines it would write a corrupt tar
      header for file sizes between 4GB and 8GB, even though no error was raised.
      This broke both "pg_dump -Ft" and pg_basebackup for such cases.
      
      * pg_restore from a tar archive would fail on tables of size between 4GB
      and 8GB, on machines where either "size_t" or "unsigned long" is 32 bits.
      This happened even with an archive file not affected by the previous bug.
      
      * pg_basebackup would fail if there were files of size between 4GB and 8GB,
      even on 64-bit machines.
      
      * In 9.3 and later, "pg_basebackup -Ft" failed entirely, for any file size,
      on 64-bit big-endian machines.
      
      In view of these potential data-loss bugs, back-patch to all supported
      branches, even though removal of the documented 8GB limit might otherwise
      be considered a new feature rather than a bug fix.
      00cdd835
  7. 20 Nov, 2015 2 commits
    • Tom Lane's avatar
      Fix handling of inherited check constraints in ALTER COLUMN TYPE (again). · 074c5cfb
      Tom Lane authored
      The previous way of reconstructing check constraints was to do a separate
      "ALTER TABLE ONLY tab ADD CONSTRAINT" for each table in an inheritance
      hierarchy.  However, that way has no hope of reconstructing the check
      constraints' own inheritance properties correctly, as pointed out in
      bug #13779 from Jan Dirk Zijlstra.  What we should do instead is to do
      a regular "ALTER TABLE", allowing recursion, at the topmost table that
      has a particular constraint, and then suppress the work queue entries
      for inherited instances of the constraint.
      
      Annoyingly, we'd tried to fix this behavior before, in commit 5ed6546c,
      but we failed to notice that it wasn't reconstructing the pg_constraint
      field values correctly.
      
      As long as I'm touching pg_get_constraintdef_worker anyway, tweak it to
      always schema-qualify the target table name; this seems like useful backup
      to the protections installed by commit 5f173040.
      
      In HEAD/9.5, get rid of get_constraint_relation_oids, which is now unused.
      (I could alternatively have modified it to also return conislocal, but that
      seemed like a pretty single-purpose API, so let's not pretend it has some
      other use.)  It's unused in the back branches as well, but I left it in
      place just in case some third-party code has decided to use it.
      
      In HEAD/9.5, also rename pg_get_constraintdef_string to
      pg_get_constraintdef_command, as the previous name did nothing to explain
      what that entry point did differently from others (and its comment was
      equally useless).  Again, that change doesn't seem like material for
      back-patching.
      
      I did a bit of re-pgindenting in tablecmds.c in HEAD/9.5, as well.
      
      Otherwise, back-patch to all supported branches.
      074c5cfb
    • Robert Haas's avatar
      Avoid server crash when worker registration fails at execution time. · 6c878a75
      Robert Haas authored
      The previous coding attempts to destroy the DSM in this case, but
      child nodes might have stored data there and still be holding onto
      pointers in this case.  So don't do that.
      
      Also, free the reader array instead of leaking it.
      
      Extracted from two different patch versions both by Amit Kapila.
      6c878a75
  8. 19 Nov, 2015 12 commits
  9. 18 Nov, 2015 4 commits
    • Tom Lane's avatar
      Accept flex > 2.5.x in configure. · 32f15d05
      Tom Lane authored
      Per buildfarm member anchovy, 2.6.0 exists in the wild now.
      Hopefully it works with Postgres; if not, we'll have to do something
      about that, but in any case claiming it's "too old" is pretty silly.
      32f15d05
    • Robert Haas's avatar
      Make a comment more precise. · e0734904
      Robert Haas authored
      Remote expressions now also matter to make_foreignscan()
      
      Noted by Etsuro Fujita.
      e0734904
    • Robert Haas's avatar
      Avoid aggregating worker instrumentation multiple times. · 166b61a8
      Robert Haas authored
      Amit Kapila, per design ideas from me.
      166b61a8
    • Robert Haas's avatar
      Fix dumb bug in tqueue.c · adeee974
      Robert Haas authored
      When I wrote this code originally, the intention was to recompute the
      remapinfo only when the tupledesc changes.  This presumably only
      happens once per query, but I copied the design pattern from other
      DestReceivers.  However, due to a silly oversight on my part,
      tqueue->tupledesc never got set, leading to recomputation for every
      tuple.
      
      This should improve the performance of parallel scans that return a
      significant number of tuples.
      
      Report by Amit Kapila; patch by me, reviewed by him.
      adeee974
  10. 17 Nov, 2015 5 commits
  11. 16 Nov, 2015 2 commits
    • Robert Haas's avatar
      Remove volatile qualifiers from bufmgr.c and freelist.c · e93b6298
      Robert Haas authored
      Prior to commit 0709b7ee, access to
      variables within a spinlock-protected critical section had to be done
      through a volatile pointer, but that should no longer be necessary.
      
      Review by Andres Freund
      e93b6298
    • Tom Lane's avatar
      Speed up ruleutils' name de-duplication code, and fix overlength-name case. · 8004953b
      Tom Lane authored
      Since commit 11e13185, ruleutils.c has
      attempted to ensure that each RTE in a query or plan tree has a unique
      alias name.  However, the code that was added for this could be quite slow,
      even as bad as O(N^3) if N identical RTE names must be replaced, as noted
      by Jeff Janes.  Improve matters by building a transient hash table within
      set_rtable_names.  The hash table in itself reduces the cost of detecting a
      duplicate from O(N) to O(1), and we can save another factor of N by storing
      the number of de-duplicated names already created for each entry, so that
      we don't have to re-try names already created.  This way is probably a bit
      slower overall for small range tables, but almost by definition, such cases
      should not be a performance problem.
      
      In principle the same problem applies to the column-name-de-duplication
      code; but in practice that seems to be less of a problem, first because
      N is limited since we don't support extremely wide tables, and second
      because duplicate column names within an RTE are fairly rare, so that in
      practice the cost is more like O(N^2) not O(N^3).  It would be very much
      messier to fix the column-name code, so for now I've left that alone.
      
      An independent problem in the same area was that the de-duplication code
      paid no attention to the identifier length limit, and would happily produce
      identifiers that were longer than NAMEDATALEN and wouldn't be unique after
      truncation to NAMEDATALEN.  This could result in dump/reload failures, or
      perhaps even views that silently behaved differently than before.  We can
      fix that by shortening the base name as needed.  Fix it for both the
      relation and column name cases.
      
      In passing, check for interrupts in set_rtable_names, just in case it's
      still slow enough to be an issue.
      
      Back-patch to 9.3 where this code was introduced.
      8004953b
  12. 15 Nov, 2015 2 commits
    • Robert Haas's avatar
      Remove accidentally-committed debugging code. · 179c97bf
      Robert Haas authored
      Amit Kapila
      179c97bf
    • Tom Lane's avatar
      Fix ruleutils.c's dumping of whole-row Vars in ROW() and VALUES() contexts. · 7745bc35
      Tom Lane authored
      Normally ruleutils prints a whole-row Var as "foo.*".  We already knew that
      that doesn't work at top level of a SELECT list, because the parser would
      treat the "*" as a directive to expand the reference into separate columns,
      not a whole-row Var.  However, Joshua Yanovski points out in bug #13776
      that the same thing happens at top level of a ROW() construct; and some
      nosing around in the parser shows that the same is true in VALUES().
      Hence, apply the same workaround already devised for the SELECT-list case,
      namely to add a forced cast to the appropriate rowtype in these cases.
      (The alternative of just printing "foo" was rejected because it is
      difficult to avoid ambiguity against plain columns named "foo".)
      
      Back-patch to all supported branches.
      7745bc35