1. 25 Aug, 2021 2 commits
  2. 24 Aug, 2021 2 commits
    • Tom Lane's avatar
      Fix regexp misbehavior with capturing parens inside "{0}". · 244dd799
      Tom Lane authored
      Regexps like "(.){0}...\1" drew an "invalid backreference number".
      That's not unreasonable on its face, since the capture group will
      never be matched if it's iterated zero times.  However, other engines
      such as Perl's don't complain about this, nor do we throw an error for
      related cases such as "(.)|\1", even though that backref can never
      succeed either.  Also, if the zero-iterations case happens at runtime
      rather than compile time --- say, "(x)*...\1" when there's no "x" to
      be found --- that's not an error, we just deem the backref to not
      match.  Making this even less defensible, no error was thrown for
      nested cases such as "((.)){0}...\2"; and to add insult to injury,
      those cases could result in assertion failures instead.  (It seems
      that nothing especially bad happened in non-assert builds, though.)
      
      Let's just fix it so that no error is thrown and instead the backref
      is deemed to never match, so that compile-time detection of no
      iterations behaves the same as run-time detection.
      
      Per report from Mark Dilger.  This appears to be an aboriginal error
      in Spencer's library, so back-patch to all supported versions.
      
      Pre-v14, it turns out to also be necessary to back-patch one aspect of
      commits cb76fbd7e/00116dee5, namely to create capture-node subREs with
      the begin/end states of their subexpressions, not the current lp/rp
      of the outer parseqatom invocation.  Otherwise delsub complains that
      we're trying to disconnect a state from itself.  This is a bit scary
      but code examination shows that it's safe: in the pre-v14 code, if we
      want to wrap iteration around the subexpression, the first thing we do
      is overwrite the atom's begin/end fields with new states.  So the
      bogus values didn't survive long enough to be used for anything, except
      if no iteration is required, in which case it doesn't matter.
      
      Discussion: https://postgr.es/m/A099E4A8-4377-4C64-A98C-3DEDDC075502@enterprisedb.com
      244dd799
    • Amit Kapila's avatar
      Fix Alter Subscription's Add/Drop Publication behavior. · 5cfcd46e
      Amit Kapila authored
      The current refresh behavior tries to just refresh added/dropped
      publications but that leads to removing wrong tables from subscription. We
      can't refresh just the dropped publication because it is quite possible
      that some of the tables are removed from publication by that time and now
      those will remain as part of the subscription. Also, there is a chance
      that the tables that were part of the publication being dropped are also
      part of another publication, so we can't remove those.
      
      So, we decided that by default, add/drop commands will also act like
      REFRESH PUBLICATION which means they will refresh all the publications. We
      can keep the old behavior for "add publication" but it is better to be
      consistent with "drop publication".
      
      Author: Hou Zhijie
      Reviewed-by: Masahiko Sawada, Amit Kapila
      Backpatch-through: 14, where it was introduced
      Discussion: https://postgr.es/m/OS0PR01MB5716935D4C2CC85A6143073F94EF9@OS0PR01MB5716.jpnprd01.prod.outlook.com
      5cfcd46e
  3. 23 Aug, 2021 3 commits
    • Tom Lane's avatar
      Prevent regexp back-refs from sometimes matching when they shouldn't. · 779557bd
      Tom Lane authored
      The recursion in cdissect() was careless about clearing match data
      for capturing parentheses after rejecting a partial match.  This
      could allow a later back-reference to succeed when by rights it
      should fail for lack of a defined referent.
      
      To fix, think a little more rigorously about what the contract
      between different levels of cdissect's recursion needs to be.
      With the right spec, we can fix this using fewer rather than more
      resets of the match data; the key decision being that a failed
      sub-match is now explicitly responsible for clearing any matches
      it may have set.
      
      There are enough other cross-checks and optimizations in the code
      that it's not especially easy to exhibit this problem; usually, the
      match will fail as-expected.  Plus, regexps that are even potentially
      vulnerable are most likely user errors, since there's just not much
      point in writing a back-ref that doesn't always have a referent.
      These facts perhaps explain why the issue hasn't been detected,
      even though it's almost certainly a couple of decades old.
      
      Discussion: https://postgr.es/m/151435.1629733387@sss.pgh.pa.us
      779557bd
    • Alvaro Herrera's avatar
      Avoid creating archive status ".ready" files too early · e3fb6170
      Alvaro Herrera authored
      WAL records may span multiple segments, but XLogWrite() does not
      wait for the entire record to be written out to disk before
      creating archive status files.  Instead, as soon as the last WAL page of
      the segment is written, the archive status file is created, and the
      archiver may process it.  If PostgreSQL crashes before it is able to
      write and flush the rest of the record (in the next WAL segment), the
      wrong version of the first segment file lingers in the archive, which
      causes operations such as point-in-time restores to fail.
      
      To fix this, keep track of records that span across segments and ensure
      that segments are only marked ready-for-archival once such records have
      been completely written to disk.
      
      This has always been wrong, so backpatch all the way back.
      
      Author: Nathan Bossart <bossartn@amazon.com>
      Reviewed-by: default avatarKyotaro Horiguchi <horikyota.ntt@gmail.com>
      Reviewed-by: default avatarRyo Matsumura <matsumura.ryo@fujitsu.com>
      Reviewed-by: default avatarAndrey Borodin <x4mmm@yandex-team.ru>
      Discussion: https://postgr.es/m/CBDDFA01-6E40-46BB-9F98-9340F4379505@amazon.com
      e3fb6170
    • Michael Paquier's avatar
      Fix backup manifests to generate correct WAL-Ranges across timelines · 65b649fe
      Michael Paquier authored
      In a backup manifest, WAL-Ranges stores the range of WAL that is
      required for the backup to be valid.  pg_verifybackup would then
      internally use pg_waldump for the checks based on this data.
      
      When the timeline where the backup started was more than 1 with a
      history file looked at for the manifest data generation, the calculation
      of the WAL range for the first timeline to check was incorrect.  The
      previous logic used as start LSN the start position of the first
      timeline, but it needs to use the start LSN of the backup.  This would
      cause failures with pg_verifybackup, or any tools making use of the
      backup manifests.
      
      This commit adds a test based on a logic using a self-promoted node,
      making it rather cheap.
      
      Author: Kyotaro Horiguchi
      Discussion: https://postgr.es/m/20210818.143031.1867083699202617521.horikyota.ntt@gmail.com
      Backpatch-through: 13
      65b649fe
  4. 21 Aug, 2021 1 commit
    • Tom Lane's avatar
      Improve error messages about misuse of SELECT INTO. · 8f6a5219
      Tom Lane authored
      Improve two places in plpgsql, and one in spi.c, where an error
      message would confusingly tell you that you couldn't use a SELECT
      query, when what you had written *was* a SELECT query.  The actual
      problem is that you can't use SELECT ... INTO in these contexts,
      but the messages failed to make that apparent.  Special-case
      SELECT INTO to make these errors more helpful.
      
      Also, fix the same spots in plpgsql, as well as several messages
      in exec_eval_expr(), to not quote the entire complained-of query or
      expression in the primary error message.  That behavior very easily
      led to violating our message style guideline about keeping the primary
      error message short and single-line.  Also, since the important part
      of the message was after the inserted text, it could make the real
      problem very hard to see.  We can report the query or expression as
      the first line of errcontext instead.
      
      Per complaint from Roger Mason.  Back-patch to v14, since (a) some
      of these messages are new in v14 and (b) v14's translatable strings
      are still somewhat in flux.  The problem's older than that of
      course, but I'm hesitant to change the behavior further back.
      
      Discussion: https://postgr.es/m/1914708.1629474624@sss.pgh.pa.us
      8f6a5219
  5. 20 Aug, 2021 3 commits
  6. 19 Aug, 2021 4 commits
    • Tom Lane's avatar
      Avoid trying to lock OLD/NEW in a rule with FOR UPDATE. · 46490039
      Tom Lane authored
      transformLockingClause neglected to exclude the pseudo-RTEs for
      OLD/NEW when processing a rule's query.  This led to odd errors
      or even crashes later on.  This bug is very ancient, but it's
      not terribly surprising that nobody noticed, since the use-case
      for SELECT FOR UPDATE in a non-view rule is somewhere between
      thin and non-existent.  Still, crashing is not OK.
      
      Per bug #17151 from Zhiyong Wu.  Thanks to Masahiko Sawada
      for analysis of the problem.
      
      Discussion: https://postgr.es/m/17151-c03a3e6e4ec9aadb@postgresql.org
      46490039
    • Andres Freund's avatar
      Unset MyBEEntry, making elog.c's call to pgstat_get_my_query_id() safe. · 18914f24
      Andres Freund authored
      Previously log messages late during shutdown could end up using either another
      backend's PgBackendStatus (multi user) or segfault (single user) because
      pgstat_get_my_query_id()'s check for !MyBEEntry didn't filter out use after
      pgstat_beshutdown_hook().
      
      This became a bug in 4f0b0966, but was a bit fishy before. But given
      there's no known problematic cases before 14, it doesn't seem worth
      backpatching further.
      
      Also fixes a wrong filename in a comment, introduced in e1025044.
      Reported-By: default avatarAndres Freund <andres@anarazel.de>
      Reviewed-By: default avatarJulien Rouhaud <rjuju123@gmail.com>
      Discussion: https://postgr.es/m/Julien Rouhaud <rjuju123@gmail.com>
      Backpatch: 14-
      18914f24
    • Amit Kapila's avatar
      Fix typo in protocol.sgml. · e1915646
      Amit Kapila authored
      The 'Stream Stop' message is misspelled as 'Stream End' in the docs.
      
      Author: Masahiko Sawada
      Backpatch-through: 14, where it was introduced
      Discussion: https://postgr.es/m/CAD21AoDeScrsHhLyEPYqN3sydg6PxAPVBboK=30xJfUVihNZDA@mail.gmail.com
      e1915646
    • Michael Paquier's avatar
      Revert refactoring of hex code to src/common/ · 1900c140
      Michael Paquier authored
      This is a combined revert of the following commits:
      - c3826f83, a refactoring piece that moved the hex decoding code to
      src/common/.  This code was cleaned up by aef8948f, as it originally
      included no overflow checks in the same way as the base64 routines in
      src/common/ used by SCRAM, making it unsafe for its purpose.
      - aef8948f, a more advanced refactoring of the hex encoding/decoding code
      to src/common/ that added sanity checks on the result buffer for hex
      decoding and encoding.  As reported by Hans Buschmann, those overflow
      checks are expensive, and it is possible to see a performance drop in
      the decoding/encoding of bytea or LOs the longer they are.  Simple SQLs
      working on large bytea values show a clear difference in perf profile.
      - ccf4e277, a cleanup made possible by aef8948f.
      
      The reverts of all those commits bring back the performance of hex
      decoding and encoding back to what it was in ~13.  Fow now and
      post-beta3, this is the simplest option.
      
      Reported-by: Hans Buschmann
      Discussion: https://postgr.es/m/1629039545467.80333@nidsa.net
      Backpatch-through: 14
      1900c140
  7. 18 Aug, 2021 2 commits
    • Tom Lane's avatar
      Fix check_agg_arguments' examination of aggregate FILTER clauses. · 61f9dae2
      Tom Lane authored
      Recursion into the FILTER clause was mis-implemented, such that a
      relevant Var or Aggref at the very top of the FILTER clause would
      be ignored.  (Of course, that'd have to be a plain boolean Var or
      boolean-returning aggregate.)  The consequence would be
      mis-identification of the correct semantic level of the aggregate,
      which could lead to not-per-spec query behavior.  If the FILTER
      expression is an aggregate, this could also lead to failure to issue
      an expected "aggregate function calls cannot be nested" error, which
      would likely result in a core dump later on, since the planner and
      executor aren't expecting such cases to appear.
      
      The root cause is that commit b560ec1b blindly copied some code
      that assumed it's recursing into a List, and thus didn't examine the
      top-level node.  To forestall questions about why this call doesn't
      look like the others, as well as possible future copy-and-paste
      mistakes, let's change all three check_agg_arguments_walker calls in
      check_agg_arguments, even though only the one for the filter clause
      is really broken.
      
      Per bug #17152 from Zhiyong Wu.  This has been wrong since we
      implemented FILTER, so back-patch to all supported versions.
      (Testing suggests that pre-v11 branches manage to avoid crashing
      in the bad-Aggref case, thanks to "redundant" checks in ExecInitAgg.
      But I'm not sure how thorough that protection is, and anyway the
      wrong-behavior issue remains, so fix 9.6 and 10 too.)
      
      Discussion: https://postgr.es/m/17152-c7f906cc1a88e61b@postgresql.org
      61f9dae2
    • Daniel Gustafsson's avatar
      Fix pg_amcheck --skip option parameter handling · 5310c61e
      Daniel Gustafsson authored
      The skip options set for all-visible and all-frozen were incorrect
      as they used space rather than hyphen, causing a syntax error when
      invoked. Also, the option for not skipping any pages at all, none,
      was documented but not implemented.
      
      Backpatch through 14 where pg_amcheck was introduced.
      
      Bug: #17149
      Reported-by: default avatarChen Jiaoqian <chenjq.jy@fujitsu.com>
      Reviewed-by: default avatarMasahiko Sawada <sawada.mshk@gmail.com>
      Discussion: https://postgr.es/m/17149-5918ea748da36b15@postgresql.org
      Backpatch-through: 14
      5310c61e
  8. 17 Aug, 2021 4 commits
    • Tom Lane's avatar
      Prevent ALTER TYPE/DOMAIN/OPERATOR from changing extension membership. · 8f51ee63
      Tom Lane authored
      If recordDependencyOnCurrentExtension is invoked on a pre-existing,
      free-standing object during an extension update script, that object
      will become owned by the extension.  In our current code this is
      possible in three cases:
      
      * Replacing a "shell" type or operator.
      * CREATE OR REPLACE overwriting an existing object.
      * ALTER TYPE SET, ALTER DOMAIN SET, and ALTER OPERATOR SET.
      
      The first of these cases is intentional behavior, as noted by the
      existing comments for GenerateTypeDependencies.  It seems like
      appropriate behavior for CREATE OR REPLACE too; at least, the obvious
      alternatives are not better.  However, the fact that it happens during
      ALTER is an artifact of trying to share code (GenerateTypeDependencies
      and makeOperatorDependencies) between the CREATE and ALTER cases.
      Since an extension script would be unlikely to ALTER an object that
      didn't already belong to the extension, this behavior is not very
      troubling for the direct target object ... but ALTER TYPE SET will
      recurse to dependent domains, and it is very uncool for those to
      become owned by the extension if they were not already.
      
      Let's fix this by redefining the ALTER cases to never change extension
      membership, full stop.  We could minimize the behavioral change by
      only changing the behavior when ALTER TYPE SET is recursing to a
      domain, but that would complicate the code and it does not seem like
      a better definition.
      
      Per bug #17144 from Alex Kozhemyakin.  Back-patch to v13 where ALTER
      TYPE SET was added.  (The other cases are older, but since they only
      affect the directly-named object, there's not enough of a problem to
      justify changing the behavior further back.)
      
      Discussion: https://postgr.es/m/17144-e67d7a8f049de9af@postgresql.org
      8f51ee63
    • Michael Meskes's avatar
      Improved ECPG warning as suggested by Michael Paquier and removed test case · e2d6da07
      Michael Meskes authored
      that triggers the warning during regression tests.
      e2d6da07
    • Daniel Gustafsson's avatar
      Set type identifier on BIO · b88377ad
      Daniel Gustafsson authored
      In OpenSSL there are two types of BIO's (I/O abstractions):
      source/sink and filters. A source/sink BIO is a source and/or
      sink of data, ie one acting on a socket or a file. A filter
      BIO takes a stream of input from another BIO and transforms it.
      In order for BIO_find_type() to be able to traverse the chain
      of BIO's and correctly find all BIO's of a certain type they
      shall have the type bit set accordingly, source/sink BIO's
      (what PostgreSQL implements) use BIO_TYPE_SOURCE_SINK and
      filter BIO's use BIO_TYPE_FILTER. In addition to these, file
      descriptor based BIO's should have the descriptor bit set,
      BIO_TYPE_DESCRIPTOR.
      
      The PostgreSQL implementation didn't set the type bits, which
      went unnoticed for a long time as it's only really relevant
      for code auditing the OpenSSL installation, or doing similar
      tasks. It is required by the API though, so this fixes it.
      
      Backpatch through 9.6 as this has been wrong for a long time.
      
      Author: Itamar Gafni
      Discussion: https://postgr.es/m/SN6PR06MB39665EC10C34BB20956AE4578AF39@SN6PR06MB3966.namprd06.prod.outlook.com
      Backpatch-through: 9.6
      b88377ad
    • Heikki Linnakangas's avatar
      doc: \123 and \x12 escapes in COPY are in database encoding. · f90c0595
      Heikki Linnakangas authored
      The backslash sequences, including \123 and \x12 escapes, are interpreted
      after encoding conversion. The docs failed to mention that.
      
      Backpatch to all supported versions.
      
      Reported-by: Andreas Grob
      Discussion: https://www.postgresql.org/message-id/17142-9181542ca1df75ab%40postgresql.org
      f90c0595
  9. 16 Aug, 2021 2 commits
    • Alvaro Herrera's avatar
      Revert analyze support for partitioned tables · b3d24cc0
      Alvaro Herrera authored
      This reverts the following commits:
      1b5617eb Describe (auto-)analyze behavior for partitioned tables
      0e69f705 Set pg_class.reltuples for partitioned tables
      41badeab Document ANALYZE storage parameters for partitioned tables
      0827e8af autovacuum: handle analyze for partitioned tables
      
      There are efficiency issues in this code when handling databases with
      large numbers of partitions, and it doesn't look like there isn't any
      trivial way to handle those.  There are some other issues as well.  It's
      now too late in the cycle for nontrivial fixes, so we'll have to let
      Postgres 14 users continue to manually deal with ANALYZE their
      partitioned tables, and hopefully we can fix the issues for Postgres 15.
      
      I kept [most of] be280cda ("Don't reset relhasindex for partitioned
      tables on ANALYZE") because while we added it due to 0827e8af, it is
      a good bugfix in its own right, since it affects manual analyze as well
      as autovacuum-induced analyze, and there's no reason to revert it.
      
      I retained the addition of relkind 'p' to tables included by
      pg_stat_user_tables, because reverting that would require a catversion
      bump.
      Also, in pg14 only, I keep a struct member that was added to
      PgStat_TabStatEntry to avoid breaking compatibility with existing stat
      files.
      
      Backpatch to 14.
      
      Discussion: https://postgr.es/m/20210722205458.f2bug3z6qzxzpx2s@alap3.anarazel.de
      b3d24cc0
    • Michael Paquier's avatar
      Refresh apply delay on reload of recovery_min_apply_delay at recovery · f83d80ea
      Michael Paquier authored
      This commit ensures that the wait interval in the replay delay loop
      waiting for an amount of time defined by recovery_min_apply_delay is
      correctly handled on reload, recalculating the delay if this GUC value
      is updated, based on the timestamp of the commit record being replayed.
      
      The previous behavior would be problematic for example with replay
      still waiting even if the delay got reduced or just cancelled.  If the
      apply delay was increased to a larger value, the wait would have just
      respected the old value set, finishing earlier.
      
      Author: Soumyadeep Chakraborty, Ashwin Agrawal
      Reviewed-by: Kyotaro Horiguchi, Michael Paquier
      Discussion: https://postgr.es/m/CAE-ML+93zfr-HLN8OuxF0BjpWJ17O5dv1eMvSE5jsj9jpnAXZA@mail.gmail.com
      Backpatch-through: 9.6
      f83d80ea
  10. 13 Aug, 2021 5 commits
    • Tom Lane's avatar
      Add RISC-V spinlock support in s_lock.h. · 4ffbd55d
      Tom Lane authored
      Like the ARM case, just use gcc's __sync_lock_test_and_set();
      that will compile into AMOSWAP.W.AQ which does what we need.
      
      At some point it might be worth doing some work on atomic ops
      for RISC-V, but this should be enough for a creditable port.
      
      Back-patch to all supported branches, just in case somebody
      wants to try them on RISC-V.
      
      Marek Szuba
      
      Discussion: https://postgr.es/m/dea97b6d-f55f-1f6d-9109-504aa7dfa421@gentoo.org
      4ffbd55d
    • Peter Eisentraut's avatar
    • Michael Meskes's avatar
      Fix connection handling for DEALLOCATE and DESCRIBE statements · a945f552
      Michael Meskes authored
      After binding a statement to a connection with DECLARE STATEMENT the connection
      was still not used for DEALLOCATE and DESCRIBE statements. This patch fixes
      that, adds a missing warning and cleans up the code.
      
      Author: Hayato Kuroda
      Reviewed-by: Kyotaro Horiguchi, Michael Paquier
      Discussion: https://postgr.es/m/TYAPR01MB5866BA57688DF2770E2F95C6F5069%40TYAPR01MB5866.jpnprd01.prod.outlook.com
      a945f552
    • Daniel Gustafsson's avatar
      Fix sslsni connparam boolean check · ffff00a3
      Daniel Gustafsson authored
      The check for sslsni only checked for existence of the parameter
      but not for the actual value of the param.  This meant that the
      SNI extension was always turned on.  Fix by inspecting the value
      of sslsni and only activate the SNI extension iff sslsni has been
      enabled.  Also update the docs to be more in line with how other
      boolean params are documented.
      
      Backpatch to 14 where sslsni was first implemented.
      
      Reviewed-by: Tom Lane
      Backpatch-through: 14, where sslni was added
      ffff00a3
    • David Rowley's avatar
      Fix incorrect hash table resizing code in simplehash.h · dc23c77d
      David Rowley authored
      This fixes a bug in simplehash.h which caused an incorrect size mask to be
      used when the hash table grew to SH_MAX_SIZE (2^32).  The code was
      incorrectly setting the size mask to 0 when the hash tables reached the
      maximum possible number of buckets.  This would result always trying to
      use the 0th bucket causing an  infinite loop of trying to grow the hash
      table due to there being too many collisions.
      
      Seemingly it's not that common for simplehash tables to ever grow this big
      as this bug dates back to v10 and nobody seems to have noticed it before.
      However, probably the most likely place that people would notice it would
      be doing a large in-memory Hash Aggregate with something close to at least
      2^31 groups.
      
      After this fix, the code now works correctly with up to within 98% of 2^32
      groups and will fail with the following error when trying to insert any
      more items into the hash table:
      
      ERROR:  hash table size exceeded
      
      However, the work_mem (or hash_mem_multiplier in newer versions) settings
      will generally cause Hash Aggregates to spill to disk long before reaching
      that many groups.  The minimal test case I did took a work_mem setting of
      over 192GB to hit the bug.
      
      simplehash hash tables are used in a few other places such as Bitmap Index
      Scans, however, again the size that the hash table can become there is
      also limited to work_mem and it would take a relation of around 16TB
      (2^31) pages and a very large work_mem setting to hit this.  With smaller
      work_mem values the table would become lossy and never grow large enough
      to hit the problem.
      
      Author: Yura Sokolov
      Reviewed-by: David Rowley, Ranier Vilela
      Discussion: https://postgr.es/m/b1f7f32737c3438136f64b26f4852b96@postgrespro.ru
      Backpatch-through: 10, where simplehash.h was added
      dc23c77d
  11. 12 Aug, 2021 3 commits
    • Thomas Munro's avatar
      Make EXEC_BACKEND more convenient on macOS. · 8201b605
      Thomas Munro authored
      It's hard to disable ASLR on current macOS releases, for testing with
      -DEXEC_BACKEND.  You could already set the environment variable
      PG_SHMEM_ADDR to something not likely to collide with mappings created
      earlier in process startup.  Let's also provide a default value that
      works on current releases and architectures, for developer convenience.
      
      As noted in the pre-existing comment, this is a horrible hack, but
      -DEXEC_BACKEND is only used by Unix-based PostgreSQL developers for
      testing some otherwise Windows-only code paths, so it seems excusable.
      
      Back-patch to all supported branches.
      Reviewed-by: default avatarTom Lane <tgl@sss.pgh.pa.us>
      Discussion: https://postgr.es/m/20210806032944.m4tz7j2w47mant26%40alap3.anarazel.de
      8201b605
    • Tomas Vondra's avatar
      Use appropriate tuple descriptor in FDW batching · 886531f3
      Tomas Vondra authored
      The FDW batching code was using the same tuple descriptor both for all
      slots (regular and plan slots), but that's incorrect - the subplan may
      use a different descriptor. Currently this is benign, because batching
      is used only for INSERTs, and in that case the descriptors always match.
      But that would change if we allow batching UPDATEs.
      
      Fix by copying the appropriate tuple descriptor. Backpatch to 14, where
      the FDW batching was implemented.
      
      Author: Amit Langote
      Backpatch-through: 14, where FDW batching was added
      Discussion: https://postgr.es/m/CA%2BHiwqEWd5B0-e-RvixGGUrNvGkjH2s4m95%3DJcwUnyV%3Df0rAKQ%40mail.gmail.com
      886531f3
    • Heikki Linnakangas's avatar
      Fix segfault during EvalPlanQual with mix of local and foreign partitions. · 6458ed18
      Heikki Linnakangas authored
      It's not sensible to re-evaluate a direct-modify Foreign Update or Delete
      during EvalPlanQual. However, ExecInitForeignScan() can still get called
      if a table mixes local and foreign partitions. EvalPlanQualStart() left
      the es_result_relations array uninitialized in the child EPQ EState, but
      ExecInitForeignScan() still expected to find it. That caused a segfault.
      
      Fix by skipping the es_result_relations lookup during EvalPlanQual
      processing. To make things a bit more robust, also skip the
      BeginDirectModify calls, and add a runtime check that ExecForeignScan()
      is not called on direct-modify foreign scans during EvalPlanQual
      processing.
      
      This is new in v14, commit 1375422c. Before that, EvalPlanQualStart()
      copied the whole ResultRelInfo array to the EPQ EState. Backpatch to v14.
      
      Report and diagnosis by Andrey Lepikhov.
      
      Discussion: https://www.postgresql.org/message-id/cb2b808d-cbaa-4772-76ee-c8809bafcf3d%40postgrespro.ru
      6458ed18
  12. 10 Aug, 2021 1 commit
    • Tom Lane's avatar
      Fix failure of btree_gin indexscans with "char" type and </<= operators. · a4957b5a
      Tom Lane authored
      As a result of confusion about whether the "char" type is signed or
      unsigned, scans for index searches like "col < 'x'" or "col <= 'x'"
      would start at the middle of the index not the left end, thus missing
      many or all of the entries they should find.  Fortunately, this
      is not a symptom of index corruption.  It's only the search logic
      that is broken, and we can fix it without unpleasant side-effects.
      
      Per report from Jason Kim.  This has been wrong since btree_gin's
      beginning, so back-patch to all supported branches.
      
      Discussion: https://postgr.es/m/20210810001649.htnltbh7c63re42p@jasonk.me
      a4957b5a
  13. 09 Aug, 2021 5 commits
  14. 08 Aug, 2021 3 commits
    • Tom Lane's avatar
      Doc: remove bogus <indexterm> items. · c905e64d
      Tom Lane authored
      Copy-and-pasteo in 665c5855e, evidently.  The 9.6 docs toolchain
      whined about duplicate index entries, though our modern toolchain
      doesn't.  In any case, these GUCs surely are not about the
      default settings of these values.
      c905e64d
    • Tom Lane's avatar
      Rethink regexp engine's backref-related compilation state. · 5227d998
      Tom Lane authored
      I had committer's remorse almost immediately after pushing cb76fbd7e,
      upon finding that removing capturing subexpressions' subREs from the
      data structure broke my proposed patch for REG_NOSUB optimization.
      Revert that data structure change.  Instead, address the concern
      about not changing capturing subREs' endpoints by not changing the
      endpoints.  We don't need to, because the point of that bit was just
      to ensure that the atom has endpoints distinct from the outer state
      pair that we're stringing the branch between.  We already made
      suitable states in the parenthesized-subexpression case, so the
      additional ones were just useless overhead.  This seems more
      understandable than Spencer's original coding, and it ought to be
      a shade faster too by saving a few state creations and arc changes.
      (I actually see a couple percent improvement on Jacobson's web
      corpus, though that's barely above the noise floor so I wouldn't
      put much stock in that result.)
      
      Also, fix the logic added by ea1268f6 to ensure that the subRE
      recorded in v->subs[subno] is exactly the one with capno == subno.
      Spencer's original coding recorded the child subRE of the capture
      node, which is okay so far as having the right endpoint states is
      concerned, but as of cb76fbd7e the capturing subRE itself always
      has those endpoints too.  I think the inconsistency is confusing
      for the REG_NOSUB optimization.
      
      As before, backpatch to v14.
      
      Discussion: https://postgr.es/m/0203588E-E609-43AF-9F4F-902854231EE7@enterprisedb.com
      5227d998
    • Tom Lane's avatar
      Make regexp engine's backref-related compilation state more bulletproof. · 5e6ad63c
      Tom Lane authored
      Up to now, we remembered the definition of a capturing parenthesis
      subexpression by storing a pointer to the associated subRE node.
      That was okay before, because that subRE didn't get modified anymore
      while parsing the rest of the regexp.  However, in the wake of
      commit ea1268f6, that's no longer true: the outer invocation of
      parseqatom() feels free to scribble on that subRE.  This seems to
      work anyway, because the states we jam into the child atom in the
      "prepare a general-purpose state skeleton" stanza aren't really
      semantically different from the original endpoints of the child atom.
      But that would be mighty easy to break, and it's definitely not how
      things worked before.
      
      Between this and the issue fixed in the prior commit, it seems best
      to get rid of this dependence on subRE nodes entirely.  We don't need
      the whole child subRE for future backrefs, only its starting and ending
      NFA states; so let's just store pointers to those.
      
      Also, in the corner case where we make an extra subRE to handle
      immediately-nested capturing parentheses, it seems like it'd be smart
      to have the extra subRE have the same begin/end states as the original
      child subRE does (s/s2 not lp/rp).  I think that linking it from lp to
      rp might actually be semantically wrong, though since Spencer's original
      code did it that way, I'm not totally certain.  Using s/s2 is certainly
      not wrong, in any case.
      
      Per report from Mark Dilger.  Back-patch to v14 where the problematic
      patches came in.
      
      Discussion: https://postgr.es/m/0203588E-E609-43AF-9F4F-902854231EE7@enterprisedb.com
      5e6ad63c