1. 19 Oct, 2020 3 commits
    • Peter Eisentraut's avatar
      Improve whitespace · afa0d53d
      Peter Eisentraut authored
      The SQL file was using a mix of tabs and spaces inconsistently.
      Convert all to spaces and adjust indentation accordingly.
      afa0d53d
    • Amit Kapila's avatar
      Change the docs for PARALLEL option of Vacuum. · 560d260d
      Amit Kapila authored
      The rules to choose the number of parallel workers to perform parallel
      vacuum operation were not clearly specified.
      
      Reported-by: Peter Eisentraut
      Author: Amit Kapila
      Backpatch-through: 13, where it was introduced
      Discussion: https://postgr.es/m/36aa8aea-61b7-eb3c-263b-648e0cb117b7@2ndquadrant.com
      560d260d
    • Michael Paquier's avatar
      Fix potential memory leak in pgcrypto · ca2a12c9
      Michael Paquier authored
      When allocating a EVP context, it would have been possible to leak some
      memory allocated directly by OpenSSL, that PostgreSQL lost track of if
      the initialization of the context allocated failed.  The cleanup can be
      done with EVP_MD_CTX_destroy().
      
      Note that EVP APIs exist since OpenSSL 0.9.7 and we have in the tree
      equivalent implementations for older versions since ce9b75db (code
      removed with 9b7cd59a as of 10~).  However, in 9.5 and 9.6, the existing
      code makes use of EVP_MD_CTX_destroy() and EVP_MD_CTX_create() without
      an equivalent implementation when building the tree with OpenSSL 0.9.6
      or older, meaning that this code is in reality broken with such versions
      since it got introduced in e2838c5.  As we have heard no complains about
      that, it does not seem worth bothering with in 9.5 and 9.6, so I have
      left that out for simplicity.
      
      Author: Michael Paquier
      Discussion: https://postgr.es/m/20201015072212.GC2305@paquier.xyz
      Backpatch-through: 9.5
      ca2a12c9
  2. 18 Oct, 2020 3 commits
    • David Rowley's avatar
      Prevent overly large and NaN row estimates in relations · a90c950f
      David Rowley authored
      Given a query with enough joins, it was possible that the query planner,
      after multiplying the row estimates with the join selectivity that the
      estimated number of rows would exceed the limits of the double data type
      and become infinite.
      
      To give an indication on how extreme a case is required to hit this, the
      particular example case reported required 379 joins to a table without any
      statistics, which resulted in the 1.0/DEFAULT_NUM_DISTINCT being used for
      the join selectivity.  This eventually caused the row estimates to go
      infinite and resulted in an assert failure in initial_cost_mergejoin()
      where the infinite row estimated was multiplied by an outerstartsel of 0.0
      resulting in NaN.  The failing assert verified that NaN <= Inf, which is
      false.
      
      To get around this we use clamp_row_est() to cap row estimates at a
      maximum of 1e100.  This value is thought to be low enough that costs
      derived from it would remain within the bounds of what the double type can
      represent.
      
      Aside from fixing the failing Assert, this also has the added benefit of
      making it so add_path() will still receive proper numerical values as
      costs which will allow it to make more sane choices when determining the
      cheaper path in extreme cases such as the one described above.
      
      Additionally, we also get rid of the isnan() checks in the join costing
      functions. The actual case which originally triggered those checks to be
      added in the first place never made it to the mailing lists.  It seems
      likely that the new code being added to clamp_row_est() will result in
      those becoming checks redundant, so just remove them.
      
      The fairly harmless assert failure problem does also exist in the
      backbranches, however, a more minimalistic fix will be applied there.
      
      Reported-by: Onder Kalaci
      Reviewed-by: Tom Lane
      Discussion: https://postgr.es/m/DM6PR21MB1211FF360183BCA901B27F04D80B0@DM6PR21MB1211.namprd21.prod.outlook.com
      a90c950f
    • Tom Lane's avatar
      Update the Winsock API version requested by libpq. · d5a9a661
      Tom Lane authored
      According to Microsoft's documentation, 2.2 has been the current
      version since Windows 98 or so.  Moreover, that's what the Postgres
      backend has been requesting since 2004 (cf commit 4cdf51e6).
      So there seems no reason for libpq to keep asking for 1.1.
      
      Bring thread_test along, too, so that we're uniformly asking for 2.2
      in all our WSAStartup calls.
      
      It's not clear whether there's any point in back-patching this,
      so for now I didn't.
      
      Discussion: https://postgr.es/m/132799.1602960277@sss.pgh.pa.us
      d5a9a661
    • Tom Lane's avatar
      In pg_restore's dump_lo_buf(), work a little harder on error handling. · 929c69aa
      Tom Lane authored
      Failure to write data to a large object during restore led to an ugly
      and uninformative error message.  To add insult to injury, it then
      fatal'd out, where other SQL-level errors usually result in pressing on.
      
      Report the underlying error condition, rather than just giving not-very-
      useful byte counts, and use warn_or_exit_horribly() so as to adhere to
      pg_restore's general policy about whether to continue or not.
      
      Also recognize that lo_write() returns int not size_t.
      
      Per report from Justin Pryzby, though I didn't use his patch.
      Given the lack of comparable complaints, I'm not sure this is
      worth back-patching.
      
      Discussion: https://postgr.es/m/20201018010232.GF9241@telsasoft.com
      929c69aa
  3. 17 Oct, 2020 4 commits
    • Tom Lane's avatar
      In libpq for Windows, call WSAStartup once and WSACleanup not at all. · 7d00a6b2
      Tom Lane authored
      The Windows documentation insists that every WSAStartup call should
      have a matching WSACleanup call.  However, if that ever had actual
      relevance, it wasn't in this century.  Every remotely-modern Windows
      kernel is capable of cleaning up when a process exits without doing
      that, and must be so to avoid resource leaks in case of a process
      crash.  Moreover, Postgres backends have done WSAStartup without
      WSACleanup since commit 4cdf51e6 in 2004, and we've never seen any
      indication of a problem with that.
      
      libpq's habit of doing WSAStartup during connection start and
      WSACleanup during shutdown is also rather inefficient, since a
      series of non-overlapping connection requests leads to repeated,
      quite expensive DLL unload/reload cycles.  We document a workaround
      for that (having the application call WSAStartup for itself), but
      that's just a kluge.  It's also worth noting that it's far from
      uncommon for applications to exit without doing PQfinish, and
      we've not heard reports of trouble from that either.
      
      However, the real reason for acting on this is that recent
      experiments by Alexander Lakhin suggest that calling WSACleanup
      during PQfinish might be triggering the symptom we occasionally see
      that a process using libpq fails to emit expected stdio output.
      
      Therefore, let's change libpq so that it calls WSAStartup only
      once per process, during the first connection attempt, and never
      calls WSACleanup at all.
      
      While at it, get rid of the only other WSACleanup call in our code
      tree, in pg_dump/parallel.c; that presumably is equally useless.
      
      If this proves to suppress the fairly-common ecpg test failures
      we see on Windows, I'll back-patch, but for now let's just do it
      in HEAD and see what happens.
      
      Discussion: https://postgr.es/m/ac976d8c-03df-d6b8-025c-15a2de8d9af1@postgrespro.ru
      7d00a6b2
    • Tom Lane's avatar
      Doc: caution against misuse of 'now' and related datetime literals. · 54084981
      Tom Lane authored
      Section 8.5.1.4, which defines these literals, made only a vague
      reference to the fact that they might be evaluated too soon to be
      safe in non-interactive contexts.  Provide a more explicit caution
      against misuse.  Also, generalize the wording in the related tip in
      section 9.9.4: while it clearly described this problem, it implied
      (or really, stated outright) that the problem only applies to table
      DEFAULT clauses.
      
      Per gripe from Tijs van Dam.  Back-patch to all supported branches.
      
      Discussion: https://postgr.es/m/c2LuRv9BiRT3bqIo5mMQiVraEXey_25B4vUn0kDqVqilwOEu_iVF1tbtvLnyQK7yDG3PFaz_GxLLPil2SDkj1MCObNRVaac-7j1dVdFERk8=@thalex.com
      54084981
    • Tom Lane's avatar
      Update time zone data files to tzdata release 2020c. · c4a803ac
      Tom Lane authored
      DST law changes in Morocco, Canadian Yukon, Fiji, Macquarie Island,
      Casey Station (Antarctica).  Historical corrections for France,
      Hungary, Monaco.
      c4a803ac
    • Tom Lane's avatar
      Sync our copy of the timezone library with IANA release tzcode2020c. · ce0e97f8
      Tom Lane authored
      This changes zic's default output format from "-b fat" to "-b slim".
      We were already using "slim" in v13/HEAD, so those branches drop
      the explicit -b switch in the Makefiles.  Instead, add an explicit
      "-b fat" in v12 and before, so that we don't change the output file
      format in those branches.  (This is perhaps excessively conservative,
      but we decided not to do so in a1207910, and I'll stick with that.)
      
      Other non-cosmetic changes are to drop support for zic's long-obsolete
      "-y" switch, and to ensure that strftime() does not change errno
      unless it fails.
      
      As usual with tzcode changes, back-patch to all supported branches.
      ce0e97f8
  4. 16 Oct, 2020 5 commits
  5. 15 Oct, 2020 16 commits
  6. 14 Oct, 2020 6 commits
  7. 13 Oct, 2020 3 commits
    • Tom Lane's avatar
      Paper over regression failures in infinite_recurse() on PPC64 Linux. · ae0f7b11
      Tom Lane authored
      Our infinite_recurse() test to verify sane stack-overrun behavior
      is affected by a bug of the Linux kernel on PPC64: it will get SIGSEGV
      if it receives a signal when the stack depth is (a) over 1MB and
      (b) within a few kB of filling the current physical stack allocation.
      See https://bugzilla.kernel.org/show_bug.cgi?id=205183.
      
      Since this test is a bit time-consuming and we run it in parallel with
      test scripts that do a lot of DDL, it can be expected to get an sinval
      catchup interrupt at some point, leading to failure if the timing is
      wrong.  This has caused more than 100 buildfarm failures over the
      past year or so.
      
      While a fix exists for the kernel bug, it might be years before that
      propagates into all production kernels, particularly in some of the
      older distros we have in the buildfarm.  For now, let's just back off
      and not run this test on Linux PPC64; that loses nothing in test
      coverage so far as our own code is concerned.
      
      To do that, split this test into a new script infinite_recurse.sql
      and skip the test when the platform name is powerpc64...-linux-gnu.
      
      Back-patch to v12.  Branches before that have not been seen to get
      this failure.  No doubt that's because the "errors" test was not
      run in parallel with other tests before commit 798070ec, greatly
      reducing the odds of an sinval catchup being necessary.
      
      I also back-patched 3c855354 into v12, just so the new regression
      script would look the same in all branches having it.
      
      Discussion: https://postgr.es/m/3479046.1602607848@sss.pgh.pa.us
      Discussion: https://postgr.es/m/20190723162703.GM22387%40telsasoft.com
      ae0f7b11
    • Heikki Linnakangas's avatar
      Create ResultRelInfos later in InitPlan, index them by RT index. · 1375422c
      Heikki Linnakangas authored
      Instead of allocating all the ResultRelInfos upfront in one big array,
      allocate them in ExecInitModifyTable(). es_result_relations is now an
      array of ResultRelInfo pointers, rather than an array of structs, and it
      is indexed by the RT index.
      
      This simplifies things: we get rid of the separate concept of a "result
      rel index", and don't need to set it in setrefs.c anymore. This also
      allows follow-up optimizations (not included in this commit yet) to skip
      initializing ResultRelInfos for target relations that were not needed at
      runtime, and removal of the es_result_relation_info pointer.
      
      The EState arrays of regular result rels and root result rels are merged
      into one array. Similarly, the resultRelations and rootResultRelations
      lists in PlannedStmt are merged into one. It's not actually clear to me
      why they were kept separate in the first place, but now that the
      es_result_relations array is indexed by RT index, it certainly seems
      pointless.
      
      The PlannedStmt->resultRelations list is now only needed for
      ExecRelationIsTargetRelation(). One visible effect of this change is that
      ExecRelationIsTargetRelation() will now return 'true' also for the
      partition root, if a partitioned table is updated. That seems like a good
      thing, although the function isn't used in core code, and I don't see any
      reason for an FDW to call it on a partition root.
      
      Author: Amit Langote
      Discussion: https://www.postgresql.org/message-id/CA%2BHiwqGEmiib8FLiHMhKB%2BCH5dRgHSLc5N5wnvc4kym%2BZYpQEQ%40mail.gmail.com
      1375422c
    • Amit Kapila's avatar
      Fix the unstable output of tests added by commit 8fccf758. · 2050832d
      Amit Kapila authored
      The test cases added by that commit were trying to test the exact number of
      times a particular transaction has spilled. However, that number can vary if
      any background transaction (say by autovacuum) happens in parallel to the main
      transaction. So let's not try to verify the exact count.
      
      Author: Amit Kapila
      Reviewed-by: Sawada Masahiko
      Discussion: https://postgr.es/m/CA+fd4k5_pPAYRTDrO2PbtTOe0eHQpBvuqmCr8ic39uTNmR49Eg@mail.gmail.com
      2050832d