1. 29 Mar, 2018 7 commits
    • Tom Lane's avatar
      Remove unnecessary BufferGetPage() calls in fsm_vacuum_page(). · 2b1759e2
      Tom Lane authored
      Just noticed that these were quite redundant, since we're holding the
      page address in a local variable anyway, and we have pin on the buffer
      throughout.
      
      Also improve a comment.
      2b1759e2
    • Tom Lane's avatar
      Remove UpdateFreeSpaceMap(), use FreeSpaceMapVacuumRange() instead. · a063baac
      Tom Lane authored
      FreeSpaceMapVacuumRange has the same effect, is more efficient if many
      pages are involved, and makes fewer assumptions about how it's used.
      Notably, Claudio Freire pointed out that UpdateFreeSpaceMap could fail
      if the specified freespace value isn't the maximum possible.  This isn't
      a problem for the single existing user, but the function represents an
      attractive nuisance IMO, because it's named as though it were a
      general-purpose update function and its limitations are undocumented.
      In any case we don't need multiple ways to get the same result.
      
      In passing, do some code review and cleanup in RelationAddExtraBlocks.
      In particular, I see no excuse for it to omit the PageIsNew safety check
      that's done in the mainline extension path in RelationGetBufferForTuple.
      
      Discussion: https://postgr.es/m/CAGTBQpYR0uJCNTt3M5GOzBRHo+-GccNO1nCaQ8yEJmZKSW5q1A@mail.gmail.com
      a063baac
    • Bruce Momjian's avatar
    • Tom Lane's avatar
      While vacuuming a large table, update upper-level FSM data every so often. · 851a26e2
      Tom Lane authored
      VACUUM updates leaf-level FSM entries immediately after cleaning the
      corresponding heap blocks.  fsmpage.c updates the intra-page search trees
      on the leaf-level FSM pages when this happens, but it does not touch the
      upper-level FSM pages, so that the released space might not actually be
      findable by searchers.  Previously, updating the upper-level pages happened
      only at the conclusion of the VACUUM run, in a single FreeSpaceMapVacuum()
      call.  This is bad because the VACUUM might get canceled before ever
      reaching that point, so that from the point of view of searchers no space
      has been freed at all, leading to table bloat.
      
      We can improve matters by updating the upper pages immediately after each
      cycle of index-cleaning and heap-cleaning, processing just the FSM pages
      corresponding to the range of heap blocks we have now fully cleaned.
      This adds a small amount of extra work, since the FSM pages leading down
      to each range boundary will be touched twice, but it's pretty negligible
      compared to everything else going on in a large VACUUM.
      
      If there are no indexes, VACUUM doesn't work in cycles but just cleans
      each heap page on first visit.  In that case we just arbitrarily update
      upper FSM pages after each 8GB of heap.  That maintains the goal of not
      letting all this work slide until the very end, and it doesn't seem worth
      expending extra complexity on a case that so seldom occurs in practice.
      
      In either case, the FSM is fully up to date before any attempt is made
      to truncate the relation, so that the most likely scenario for VACUUM
      cancellation no longer results in out-of-date upper FSM pages.  When
      we do successfully truncate, adjusting the FSM to reflect that is now
      fully handled within FreeSpaceMapTruncateRel.
      
      Claudio Freire, reviewed by Masahiko Sawada and Jing Wang, some additional
      tweaks by me
      
      Discussion: https://postgr.es/m/CAGTBQpYR0uJCNTt3M5GOzBRHo+-GccNO1nCaQ8yEJmZKSW5q1A@mail.gmail.com
      851a26e2
    • Teodor Sigaev's avatar
      Add casts from jsonb · c0cbe00f
      Teodor Sigaev authored
      Add explicit cast from scalar jsonb to all numeric and bool types. It would be
      better to have cast from scalar jsonb to text too but there is already a cast
      from jsonb to text as just text representation of json. There is no way to have
      two different casts for the same type's pair.
      
      Bump catalog version
      
      Author: Anastasia Lubennikova with editorization by Nikita Glukhov and me
      Review by: Aleksander Alekseev, Nikita Glukhov, Darafei Praliaskouski
      Discussion: https://www.postgresql.org/message-id/flat/0154d35a-24ae-f063-5273-9ffcdf1c7f2e@postgrespro.ru
      c0cbe00f
    • Bruce Momjian's avatar
      docs: fix INSTALL.xml build by using "standalone-ignore" · 7fe04ce9
      Bruce Momjian authored
      Was broken by "jit" link.
      7fe04ce9
    • Magnus Hagander's avatar
      Fix typo in comment · 669820a3
      Magnus Hagander authored
      Arthur Zakirov, confirmed by Thomas Munro
      669820a3
  2. 28 Mar, 2018 20 commits
    • Peter Eisentraut's avatar
      Allow committing inside cursor loop · 056a5a3f
      Peter Eisentraut authored
      Previously, committing or aborting inside a cursor loop was prohibited
      because that would close and remove the cursor.  To allow that,
      automatically convert such cursors to holdable cursors so they survive
      commits or rollbacks.  Portals now have a new state "auto-held", which
      means they have been converted automatically from pinned.  An auto-held
      portal is kept on transaction commit or rollback, but is still removed
      when returning to the main loop on error.
      
      This supports all languages that have cursor loop constructs: PL/pgSQL,
      PL/Python, PL/Perl.
      Reviewed-by: default avatarIldus Kurbangaliev <i.kurbangaliev@postgrespro.ru>
      056a5a3f
    • Bruce Momjian's avatar
      C comment: fix typo, log -> lag · a2894cce
      Bruce Momjian authored
      Reported-by: atorikoshi
      
      Discussion: https://postgr.es/m/b61f2ab9-c0e0-d33d-ce3f-42a228025681@lab.ntt.co.jp
      
      Author: atorikoshi
      a2894cce
    • Andres Freund's avatar
      Fix mistakes in the just added JIT docs. · a0a08c1d
      Andres Freund authored
      Reported-By: Lukas Fittl
      Author: Andres Freund
      a0a08c1d
    • Andres Freund's avatar
      Add documentation for the JIT feature. · e6c039d1
      Andres Freund authored
      As promised in earlier commits, this adds documentation about the new
      build options, the new GUCs, about the planner logic when JIT is used,
      and the benefits of JIT in general.
      
      Also adds a more implementation oriented README.
      
      I'm sure we're going to want to expand this further, but I think this
      is a reasonable start.
      
      Author: Andres Freund, with contributions by Thomas Munro
      Reviewed-By: Thomas Munro
      Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de
      e6c039d1
    • Andres Freund's avatar
      Add EXPLAIN support for JIT. · 1f0c6a9e
      Andres Freund authored
      This just shows a few details about JITing, e.g. how many functions
      have been JITed, and how long that took.  To avoid noise in regression
      tests with functions sometimes being JITed in --with-llvm builds,
      disable display when COSTS OFF is specified.
      
      Author: Andres Freund
      Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de
      1f0c6a9e
    • Andres Freund's avatar
      Add inlining support to LLVM JIT provider. · 9370462e
      Andres Freund authored
      This provides infrastructure to allow JITed code to inline code
      implemented in C. This e.g. can be postgres internal functions or
      extension code.
      
      This already speeds up long running queries, by allowing the LLVM
      optimizer to optimize across function boundaries. The optimization
      potential currently doesn't reach its full potential because LLVM
      cannot optimize the FunctionCallInfoData argument fully away, because
      it's allocated on the heap rather than the stack. Fixing that is
      beyond what's realistic for v11.
      
      To be able to do that, use CLANG to convert C code to LLVM bitcode,
      and have LLVM build a summary for it. That bitcode can then be used to
      to inline functions at runtime. For that the bitcode needs to be
      installed. Postgres bitcode goes into $pkglibdir/bitcode/postgres,
      extensions go into equivalent directories.  PGXS has been modified so
      that happens automatically if postgres has been compiled with LLVM
      support.
      
      Currently this isn't the fastest inline implementation, modules are
      reloaded from disk during inlining. That's to work around an apparent
      LLVM bug, triggering an apparently spurious error in LLVM assertion
      enabled builds.  Once that is resolved we can remove the superfluous
      read from disk.
      
      Docs will follow in a later commit containing docs for the whole JIT
      feature.
      
      Author: Andres Freund
      Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de
      9370462e
    • Andres Freund's avatar
      Use isinf builtin for clang, for performance. · 8a934d67
      Andres Freund authored
      When compiling with clang glibc's definition of isinf() ends up
      leading to and external libc function call. That's because there was a
      bug in the builtin in an old gcc version, and clang claims
      compatibility with an older version.  That causes clang to be
      measurably slower for floating point heavy workloads than gcc.
      
      To fix simply redirect isinf when using clang and clang confirms it
      has __builtin_isinf().
      8a934d67
    • Fujii Masao's avatar
      Make pg_rewind skip files and directories that are removed during server start. · 266b6acb
      Fujii Masao authored
      The target cluster that was rewound needs to perform recovery from
      the checkpoint created at failover, which leads it to remove or recreate
      some files and directories that may have been copied from the source
      cluster. So pg_rewind can skip synchronizing such files and directories,
      and which reduces the amount of data transferred during a rewind
      without changing the usefulness of the operation.
      
      Author: Michael Paquier
      Reviewed-by: Anastasia Lubennikova, Stephen Frost and me
      
      Discussion: https://postgr.es/m/20180205071022.GA17337@paquier.xyz
      266b6acb
    • Fujii Masao's avatar
      Fix handling of files that source server removes during pg_rewind is running. · 09e96b3f
      Fujii Masao authored
      After processing the filemap to build the list of chunks that will be
      fetched from the source to rewing the target server, it is possible that
      a file which was previously processed is removed from the source.  A
      simple example of such an occurence is a WAL segment which gets recycled
      on the target in-between.  When the filemap is processed, files not
      categorized as relation files are first truncated to prepare for its
      full copy of which is going to be taken from the source, divided into a
      set of junks.  However, for a recycled WAL segment, this would result in
      a segment which has a zero-byte size.  With such an empty file,
      post-rewind recovery thinks that records are saved but they are actually
      not because of the truncation which happened when processing the
      filemap, resulting in data loss.
      
      In order to fix the problem, make sure that files which are found as
      removed on the source when receiving chunks of them are as well deleted
      on the target server for consistency.
      
      Back-patch to 9.5 where pg_rewind was added.
      
      Author: Tsunakawa Takayuki
      Reviewed-by: Michael Paquier
      Reported-by: Tsunakawa Takayuki
      
      Discussion: https://postgr.es/m/0A3221C70F24FB45833433255569204D1F8DAAA2%40G01JPEXMBYT05
      09e96b3f
    • Peter Eisentraut's avatar
      PL/pgSQL: Nested CALL with transactions · d92bc83c
      Peter Eisentraut authored
      So far, a nested CALL or DO in PL/pgSQL would not establish a context
      where transaction control statements were allowed.  This fixes that by
      handling CALL and DO specially in PL/pgSQL, passing the atomic/nonatomic
      execution context through and doing the required management around
      transaction boundaries.
      Reviewed-by: default avatarTomas Vondra <tomas.vondra@2ndquadrant.com>
      d92bc83c
    • Tom Lane's avatar
      Fix actual and potential double-frees around tuplesort usage. · c2d4eb1b
      Tom Lane authored
      tuplesort_gettupleslot() passed back tuples allocated in the tuplesort's
      own memory context, even when the caller was responsible to free them.
      This created a double-free hazard, because some callers might destroy
      the tuplesort object (via tuplesort_end) before trying to clean up the
      last returned tuple.  To avoid this, change the API to specify that the
      tuple is allocated in the caller's memory context.  v10 and HEAD already
      did things that way, but in 9.5 and 9.6 this is a live bug that can
      demonstrably cause crashes with some grouping-set usages.
      
      In 9.5 and 9.6, this requires doing an extra tuple copy in some cases,
      which is unfortunate.  But the amount of refactoring needed to avoid it
      seems excessive for a back-patched change, especially since the cases
      where an extra copy happens are less performance-critical.
      
      Likewise change tuplesort_getdatum() to return pass-by-reference Datums
      in the caller's context not the tuplesort's context.  There seem to be
      no live bugs among its callers, but clearly the same sort of situation
      could happen in future.
      
      For other tuplesort fetch routines, continue to allocate the memory in
      the tuplesort's context.  This is a little inconsistent with what we now
      do for tuplesort_gettupleslot() and tuplesort_getdatum(), but that's
      preferable to adding new copy overhead in the back branches where it's
      clearly unnecessary.  These other fetch routines provide the weakest
      possible guarantees about tuple memory lifespan from v10 on, anyway,
      so this actually seems more consistent overall.
      
      Adjust relevant comments to reflect these API redefinitions.
      
      Arguably, we should change the pre-9.5 branches as well, but since
      there are no known failure cases there, it seems not worth the risk.
      
      Peter Geoghegan, per report from Bernd Helmle.  Reviewed by Kyotaro
      Horiguchi; thanks also to Andreas Seltenreich for extracting a
      self-contained test case.
      
      Discussion: https://postgr.es/m/1512661638.9720.34.camel@oopsware.de
      c2d4eb1b
    • Simon Riggs's avatar
      Store 2PC GID in commit/abort WAL recs for logical decoding · 1eb6d652
      Simon Riggs authored
      Store GID of 2PC in commit/abort WAL records when wal_level = logical.
      This allows logical decoding to send the SAME gid to subscribers
      across restarts of logical replication.
      
      Track relica origin replay progress for 2PC.
      
      (Edited from patch 0003 in the logical decoding 2PC series.)
      
      Authors: Nikhil Sontakke, Stas Kelvich
      Reviewed-by: Simon Riggs, Andres Freund
      1eb6d652
    • Peter Eisentraut's avatar
      75e95dd7
    • Peter Eisentraut's avatar
      Fix jsonb_plpython tests on older Python versions · e81fc9b9
      Peter Eisentraut authored
      Rewrite one test to avoid a case where some Python versions have output
      format differences (Decimal('1') vs Decimal("1")).
      e81fc9b9
    • Peter Eisentraut's avatar
      Transforms for jsonb to PL/Python · 3f44e3db
      Peter Eisentraut authored
      Add a new contrib module jsonb_plpython that provide a transform between
      jsonb and PL/Python.  jsonb values are converted to appropriate Python
      types such as dicts and lists, and vice versa.
      
      Author: Anthony Bykov <a.bykov@postgrespro.ru>
      Reviewed-by: default avatarAleksander Alekseev <a.alekseev@postgrespro.ru>
      Reviewed-by: default avatarNikita Glukhov <n.gluhov@postgrespro.ru>
      3f44e3db
    • Andrew Dunstan's avatar
      a437551a
    • Simon Riggs's avatar
      Use pg_stat_get_xact* functions within xacts · 5b0d7f69
      Simon Riggs authored
      Resolve build farm failures from c203d6cf,
      diagnosed by Tom Lane.
      
      The output of pg_stat_get_xact_tuples_hot_updated() and friends
      is not guaranteed to show anything after the transaction completes.
      Data is flushed slowly to stats collector, so using them can
      give timing issues.
      5b0d7f69
    • Andres Freund's avatar
      Quick adaption of JIT tuple deforming to the fast default patch. · f4f5845b
      Andres Freund authored
      Instead using memset to set tts_isnull, call the new
      slot_getmissingattrs().
      
      Also fix a bug (= instead of >=) in the code generation. Normally = is
      correct, but when repeatedly deforming fields not in a
      tuple (e.g. deform up to natts + 1 and then natts + 2) >= is needed.
      
      Discussion: https://postgr.es/m/20180328010053.i2qvsuuusst4lgmc@alap3.anarazel.de
      f4f5845b
    • Andres Freund's avatar
      Add catversion bump missed in 16828d5c. · b4013b8e
      Andres Freund authored
      Given that pg_attribute changed its layout...
      b4013b8e
    • Andrew Dunstan's avatar
      Fast ALTER TABLE ADD COLUMN with a non-NULL default · 16828d5c
      Andrew Dunstan authored
      Currently adding a column to a table with a non-NULL default results in
      a rewrite of the table. For large tables this can be both expensive and
      disruptive. This patch removes the need for the rewrite as long as the
      default value is not volatile. The default expression is evaluated at
      the time of the ALTER TABLE and the result stored in a new column
      (attmissingval) in pg_attribute, and a new column (atthasmissing) is set
      to true. Any existing row when fetched will be supplied with the
      attmissingval. New rows will have the supplied value or the default and
      so will never need the attmissingval.
      
      Any time the table is rewritten all the atthasmissing and attmissingval
      settings for the attributes are cleared, as they are no longer needed.
      
      The most visible code change from this is in heap_attisnull, which
      acquires a third TupleDesc argument, allowing it to detect a missing
      value if there is one. In many cases where it is known that there will
      not be any (e.g.  catalog relations) NULL can be passed for this
      argument.
      
      Andrew Dunstan, heavily modified from an original patch from Serge
      Rielau.
      Reviewed by Tom Lane, Andres Freund, Tomas Vondra and David Rowley.
      
      Discussion: https://postgr.es/m/31e2e921-7002-4c27-59f5-51f08404c858@2ndQuadrant.com
      16828d5c
  3. 27 Mar, 2018 7 commits
    • Tom Lane's avatar
      Update pgindent's typedefs blacklist, and make it easier to adjust. · ef1978d6
      Tom Lane authored
      It seems that all buildfarm members are now using the <stdbool.h> code
      path, so that none of them report "bool" as a typedef.  We still need it
      to be treated that way, so adjust pgindent to force that whether or not
      it's in the given list.
      
      Also, the recent introduction of LLVM infrastructure has caused the
      appearance of some typedef names that we definitely *don't* want
      treated as typedefs, such as "string" and "abs".  Extend the existing
      blacklist to include these.  (Additions based on comparing v10's
      typedefs list to what the buildfarm is currently emitting.)
      
      Rearrange the code so that the lists of whitelisted/blacklisted
      names are a bit easier to find and modify.
      
      Andrew Dunstan and Tom Lane
      
      Discussion: https://postgr.es/m/28690.1521912334@sss.pgh.pa.us
      ef1978d6
    • Tom Lane's avatar
      Allow memory contexts to have both fixed and variable ident strings. · 442accc3
      Tom Lane authored
      Originally, we treated memory context names as potentially variable in
      all cases, and therefore always copied them into the context header.
      Commit 9fa6f00b rethought this a little bit and invented a distinction
      between fixed and variable names, skipping the copy step for the former.
      But we can make things both simpler and more useful by instead allowing
      there to be two parts to a context's identification, a fixed "name" and
      an optional, variable "ident".  The name supplied in the context create
      call is now required to be a compile-time-constant string in all cases,
      as it is never copied but just pointed to.  The "ident" string, if
      wanted, is supplied later.  This is needed because typically we want
      the ident to be stored inside the context so that it's cleaned up
      automatically on context deletion; that means it has to be copied into
      the context before we can set the pointer.
      
      The cost of this approach is basically just an additional pointer field
      in struct MemoryContextData, which isn't much overhead, and is bought
      back entirely in the AllocSet case by not needing a headerSize field
      anymore, since we no longer have to cope with variable header length.
      In addition, we can simplify the internal interfaces for memory context
      creation still further, saving a few cycles there.  And it's no longer
      true that a custom identifier disqualifies a context from participating
      in aset.c's freelist scheme, so possibly there's some win on that end.
      
      All the places that were using non-compile-time-constant context names
      are adjusted to put the variable info into the "ident" instead.  This
      allows more effective identification of those contexts in many cases;
      for example, subsidary contexts of relcache entries are now identified
      by both type (e.g. "index info") and relname, where before you got only
      one or the other.  Contexts associated with PL function cache entries
      are now identified more fully and uniformly, too.
      
      I also arranged for plancache contexts to use the query source string
      as their identifier.  This is basically free for CachedPlanSources, as
      they contained a copy of that string already.  We pay an extra pstrdup
      to do it for CachedPlans.  That could perhaps be avoided, but it would
      make things more fragile (since the CachedPlanSource is sometimes
      destroyed first).  I suspect future improvements in error reporting will
      require CachedPlans to have a copy of that string anyway, so it's not
      clear that it's worth moving mountains to avoid it now.
      
      This also changes the APIs for context statistics routines so that the
      context-specific routines no longer assume that output goes straight
      to stderr, nor do they know all details of the output format.  This
      is useful immediately to reduce code duplication, and it also allows
      for external code to do something with stats output that's different
      from printing to stderr.
      
      The reason for pushing this now rather than waiting for v12 is that
      it rethinks some of the API changes made by commit 9fa6f00b.  Seems
      better for extension authors to endure just one round of API changes
      not two.
      
      Discussion: https://postgr.es/m/CAB=Je-FdtmFZ9y9REHD7VsSrnCkiBhsA4mdsLKSPauwXtQBeNA@mail.gmail.com
      442accc3
    • Simon Riggs's avatar
      Allow HOT updates for some expression indexes · c203d6cf
      Simon Riggs authored
      If the value of an index expression is unchanged after UPDATE,
      allow HOT updates where previously we disallowed them, giving
      a significant performance boost in those cases.
      
      Particularly useful for indexes such as JSON->>field where the
      JSON value changes but the indexed value does not.
      
      Submitted as "surjective indexes" patch, now enabled by use
      of new "recheck_on_update" parameter.
      
      Author: Konstantin Knizhnik
      Reviewer: Simon Riggs, with much wordsmithing and some cleanup
      c203d6cf
    • Peter Eisentraut's avatar
      libpq: PQhost to return active connected host or hostaddr · 1944cdc9
      Peter Eisentraut authored
      Previously, PQhost didn't return the connected host details when the
      connection type was CHT_HOST_ADDRESS (i.e., via hostaddr).  Instead, it
      returned the complete host connection parameter (which could contain
      multiple hosts) or the default host details, which was confusing and
      arguably incorrect.
      
      Change this to return the actually connected host or hostaddr
      irrespective of the connection type.  When hostaddr but no host was
      specified, hostaddr is now returned.  Never return the original host
      connection parameter, and document that PQhost cannot be relied on
      before the connection is established.
      
      PQport is similarly changed to always return the active connection port
      and never the original connection parameter.
      
      Author: Hari Babu <kommi.haribabu@gmail.com>
      Reviewed-by: default avatarMichael Paquier <michael@paquier.xyz>
      Reviewed-by: default avatarKyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>
      Reviewed-by: default avatarDavid G. Johnston <david.g.johnston@gmail.com>
      1944cdc9
    • Teodor Sigaev's avatar
      Fix count of skipped test of basebackup on Windows · 44bd9584
      Teodor Sigaev authored
      Commit 920a5e50 add tests which should be
      skipped on Windows boxes, but patch doesn't contain right count of them.
      
      David Steel
      44bd9584
    • Teodor Sigaev's avatar
      Skip temp tables from basebackup. · 920a5e50
      Teodor Sigaev authored
      Do not store temp tables in basebackup, they will not be visible anyway, so,
      there are not reasons to store them.
      
      Author: David Steel
      Reviewed by: me
      Discussion: https://www.postgresql.org/message-id/flat/5ea4d26a-a453-c1b7-eff9-5a3ef8f8aceb@pgmasters.net
      920a5e50
    • Teodor Sigaev's avatar
      Add predicate locking for GiST · 3ad55863
      Teodor Sigaev authored
      Add page-level predicate locking, due to gist's code organization, patch seems
      close to trivial: add check before page changing, add predicate lock before page
      scanning.  Although choosing right place to check is not simple: it should not
      be called during index build, it should support insertion of new downlink and so
      on.
      
      Author: Shubham Barai with editorization by me and Alexander Korotkov
      Reviewed by: Alexander Korotkov, Andrey Borodin, me
      Discussion: https://www.postgresql.org/message-id/flat/CALxAEPtdcANpw5ePU3LvnTP8HCENFw6wygupQAyNBgD-sG3h0g@mail.gmail.com
      3ad55863
  4. 26 Mar, 2018 6 commits