Skip to content
Snippets Groups Projects
  1. Mar 13, 2017
    • Noah Misch's avatar
      Use wrappers of PG_DETOAST_DATUM_PACKED() more. · 3a0d4731
      Noah Misch authored
      This makes almost all core code follow the policy introduced in the
      previous commit.  Specific decisions:
      
      - Text search support functions with char* and length arguments, such as
        prsstart and lexize, may receive unaligned strings.  I doubt
        maintainers of non-core text search code will notice.
      
      - Use plain VARDATA() on values detoasted or synthesized earlier in the
        same function.  Use VARDATA_ANY() on varlenas sourced outside the
        function, even if they happen to always have four-byte headers.  As an
        exception, retain the universal practice of using VARDATA() on return
        values of SendFunctionCall().
      
      - Retain PG_GETARG_BYTEA_P() in pageinspect.  (Page images are too large
        for a one-byte header, so this misses no optimization.)  Sites that do
        not call get_page_from_raw() typically need the four-byte alignment.
      
      - For now, do not change btree_gist.  Its use of four-byte headers in
        memory is partly entangled with storage of 4-byte headers inside
        GBT_VARKEY, on disk.
      
      - For now, do not change gtrgm_consistent() or gtrgm_distance().  They
        incorporate the varlena header into a cache, and there are multiple
        credible implementation strategies to consider.
      3a0d4731
    • Noah Misch's avatar
      Fix pg_file_write() error handling. · 944a026b
      Noah Misch authored
      Detect fclose() failures; given "ln -s /dev/full $PGDATA/devfull",
      "pg_file_write('devfull', 'x', true)" now fails as it should.  Don't
      leak a stream when fwrite() fails.  Remove a born-ineffective test that
      aimed to skip zero-length writes.  Back-patch to 9.2 (all supported
      versions).
      944a026b
    • Noah Misch's avatar
      Assume deconstruct_array() outputs are untoasted. · 2fd26b23
      Noah Misch authored
      In functions that issue a deconstruct_array() call, consistently use
      plain VARSIZE()/VARDATA() on the array elements.  Prior practice was
      divided between those and VARSIZE_ANY_EXHDR()/VARDATA_ANY().
      2fd26b23
  2. Mar 11, 2017
  3. Mar 10, 2017
  4. Mar 09, 2017
    • Stephen Frost's avatar
      Add relkind checks to certain contrib modules · c08d82f3
      Stephen Frost authored
      The contrib extensions pageinspect, pg_visibility and pgstattuple only
      work against regular relations which have storage.  They don't work
      against foreign tables, partitioned (parent) tables, views, et al.
      
      Add checks to the user-callable functions to return a useful error
      message to the user if they mistakenly pass an invalid relation to a
      function which doesn't accept that kind of relation.
      
      In passing, improve some of the existing checks to use ereport() instead
      of elog(), add a function to consolidate common checks where
      appropriate, and add some regression tests.
      
      Author: Amit Langote, with various changes by me
      Reviewed by: Michael Paquier and Corey Huinker
      Discussion: https://postgr.es/m/ab91fd9d-4751-ee77-c87b-4dd704c1e59c@lab.ntt.co.jp
      c08d82f3
  5. Mar 08, 2017
    • Alvaro Herrera's avatar
      Support XMLTABLE query expression · fcec6caa
      Alvaro Herrera authored
      XMLTABLE is defined by the SQL/XML standard as a feature that allows
      turning XML-formatted data into relational form, so that it can be used
      as a <table primary> in the FROM clause of a query.
      
      This new construct provides significant simplicity and performance
      benefit for XML data processing; what in a client-side custom
      implementation was reported to take 20 minutes can be executed in 400ms
      using XMLTABLE.  (The same functionality was said to take 10 seconds
      using nested PostgreSQL XPath function calls, and 5 seconds using
      XMLReader under PL/Python).
      
      The implemented syntax deviates slightly from what the standard
      requires.  First, the standard indicates that the PASSING clause is
      optional and that multiple XML input documents may be given to it; we
      make it mandatory and accept a single document only.  Second, we don't
      currently support a default namespace to be specified.
      
      This implementation relies on a new executor node based on a hardcoded
      method table.  (Because the grammar is fixed, there is no extensibility
      in the current approach; further constructs can be implemented on top of
      this such as JSON_TABLE, but they require changes to core code.)
      
      Author: Pavel Stehule, Álvaro Herrera
      Extensively reviewed by: Craig Ringer
      Discussion: https://postgr.es/m/CAFj8pRAgfzMD-LoSmnMGybD0WsEznLHWap8DO79+-GTRAPR4qA@mail.gmail.com
      fcec6caa
  6. Mar 07, 2017
  7. Mar 01, 2017
  8. Feb 27, 2017
    • Peter Eisentraut's avatar
      chomp PQerrorMessage() in backend uses · 2ed193c9
      Peter Eisentraut authored
      PQerrorMessage() returns an error message with a trailing newline, but
      in backend use (dblink, postgres_fdw, libpqwalreceiver), we want to have
      the error message without that for emitting via ereport().  To simplify
      that, add a function pchomp() that returns a pstrdup'ed string with the
      trailing newline characters removed.
      2ed193c9
  9. Feb 25, 2017
    • Tom Lane's avatar
      Remove useless duplicate inclusions of system header files. · 9e3755ec
      Tom Lane authored
      c.h #includes a number of core libc header files, such as <stdio.h>.
      There's no point in re-including these after having read postgres.h,
      postgres_fe.h, or c.h; so remove code that did so.
      
      While at it, also fix some places that were ignoring our standard pattern
      of "include postgres[_fe].h, then system header files, then other Postgres
      header files".  While there's not any great magic in doing it that way
      rather than system headers last, it's silly to have just a few files
      deviating from the general pattern.  (But I didn't attempt to enforce this
      globally, only in files I was touching anyway.)
      
      I'd be the first to say that this is mostly compulsive neatnik-ism,
      but over time it might save enough compile cycles to be useful.
      9e3755ec
  10. Feb 23, 2017
  11. Feb 22, 2017
    • Tom Lane's avatar
      Fix contrib/pg_trgm's extraction of trigrams from regular expressions. · 9e43e871
      Tom Lane authored
      The logic for removing excess trigrams from the result was faulty.
      It intends to avoid merging the initial and final states of the NFA,
      which is necessary, but in testing whether removal of a specific trigram
      would cause that, it failed to consider the combined effects of all the
      state merges that that trigram's removal would cause.  This could result
      in a broken final graph that would never match anything, leading to GIN
      or GiST indexscans not finding anything.
      
      To fix, add a "tentParent" field that is used only within this loop,
      and set it to show state merges that we are tentatively going to do.
      While examining a particular arc, we must chase up through tentParent
      links as well as regular parent links (the former can only appear atop
      the latter), and we must account for state init/fin flag merges that
      haven't actually been done yet.
      
      To simplify the latter, combine the separate init and fin bool fields
      into a bitmap flags field.  I also chose to get rid of the "children"
      state list, which seems entirely inessential.
      
      Per bug #14563 from Alexey Isayko, which the added test cases are based on.
      Back-patch to 9.3 where this code was added.
      
      Report: https://postgr.es/m/20170222111446.1256.67547@wrigleys.postgresql.org
      Discussion: https://postgr.es/m/8816.1487787594@sss.pgh.pa.us
      9e43e871
    • Robert Haas's avatar
      Fix incorrect typecast. · b4316928
      Robert Haas authored
      Ashutosh Sharma, per a report from Mithun Cy.
      
      Discussion: http://postgr.es/m/CAD__OujgqNNnCujeFTmKpjNu+W4smS8Hbi=RcWAhf1ZUs3H4WA@mail.gmail.com
      b4316928
  12. Feb 21, 2017
    • Peter Eisentraut's avatar
      Drop support for Python 2.3 · 04aad401
      Peter Eisentraut authored
      There is no specific reason for this right now, but keeping support for
      old Python versions around indefinitely increases the maintenance
      burden.  The oldest supported Python version is now Python 2.4, which is
      still shipped in RHEL/CentOS 5 by default.
      
      In configure, add a check for the required Python version and give a
      friendly error message for an old version, instead of relying on an
      obscure build error later on.
      04aad401
  13. Feb 15, 2017
    • Robert Haas's avatar
      Add optimizer and executor support for parallel index scans. · 5262f7a4
      Robert Haas authored
      In combination with 569174f1, which
      taught the btree AM how to perform parallel index scans, this allows
      parallel index scan plans on btree indexes.  This infrastructure
      should be general enough to support parallel index scans for other
      index AMs as well, if someone updates them to support parallel
      scans.
      
      Amit Kapila, reviewed and tested by Anastasia Lubennikova, Tushar
      Ahuja, and Haribabu Kommi, and me.
      5262f7a4
  14. Feb 13, 2017
    • Robert Haas's avatar
      Remove contrib/tsearch2. · 7ada2d31
      Robert Haas authored
      This module was intended to ease migrations of applications that used
      the pre-8.3 version of text search to the in-core version introduced
      in that release.  However, since all pre-8.3 releases of the database
      have been out of support for more than 5 years at this point, we
      expect that few people are depending on it at this point.  If some
      people still need it, nothing prevents it from being maintained as a
      separate extension, outside of core.
      
      Discussion: http://postgr.es/m/CA+Tgmob5R8aDHiFRTQsSJbT1oreKg2FOSBrC=2f4tqEH3dOMAg@mail.gmail.com
      7ada2d31
  15. Feb 09, 2017
    • Robert Haas's avatar
      Remove all references to "xlog" from SQL-callable functions in pg_proc. · 806091c9
      Robert Haas authored
      Commit f82ec32a renamed the pg_xlog
      directory to pg_wal.  To make things consistent, and because "xlog" is
      terrible terminology for either "transaction log" or "write-ahead log"
      rename all SQL-callable functions that contain "xlog" in the name to
      instead contain "wal".  (Note that this may pose an upgrade hazard for
      some users.)
      
      Similarly, rename the xlog_position argument of the functions that
      create slots to be called wal_position.
      
      Discussion: https://www.postgresql.org/message-id/CA+Tgmob=YmA=H3DbW1YuOXnFVgBheRmyDkWcD9M8f=5bGWYEoQ@mail.gmail.com
      806091c9
    • Robert Haas's avatar
      pageinspect: Fix hash_bitmap_info not to read the underlying page. · fc8219dc
      Robert Haas authored
      It did that to verify that the page was an overflow page rather than
      anything else, but that means that checking the status of all the
      overflow bits requires reading the entire index.  So don't do that.
      The new code validates that the page is not a primary bucket page
      or bitmap page by looking at the metapage, so that using this on
      large numbers of pages can be reasonably efficient.
      
      Ashutosh Sharma, per a complaint from me, and with further
      modifications by me.
      fc8219dc
    • Tom Lane's avatar
      Allow index AMs to cache data across aminsert calls within a SQL command. · 86d911ec
      Tom Lane authored
      It's always been possible for index AMs to cache data across successive
      amgettuple calls within a single SQL command: the IndexScanDesc.opaque
      field is meant for precisely that.  However, no comparable facility
      exists for amortizing setup work across successive aminsert calls.
      This patch adds such a feature and teaches GIN, GIST, and BRIN to use it
      to amortize catalog lookups they'd previously been doing on every call.
      (The other standard index AMs keep everything they need in the relcache,
      so there's little to improve there.)
      
      For GIN, the overall improvement in a statement that inserts many rows
      can be as much as 10%, though it seems a bit less for the other two.
      In addition, this makes a really significant difference in runtime
      for CLOBBER_CACHE_ALWAYS tests, since in those builds the repeated
      catalog lookups are vastly more expensive.
      
      The reason this has been hard up to now is that the aminsert function is
      not passed any useful place to cache per-statement data.  What I chose to
      do is to add suitable fields to struct IndexInfo and pass that to aminsert.
      That's not widening the index AM API very much because IndexInfo is already
      within the ken of ambuild; in fact, by passing the same info to aminsert
      as to ambuild, this is really removing an inconsistency in the AM API.
      
      Discussion: https://postgr.es/m/27568.1486508680@sss.pgh.pa.us
      86d911ec
  16. Feb 07, 2017
    • Robert Haas's avatar
      Cache hash index's metapage in rel->rd_amcache. · 293e24e5
      Robert Haas authored
      This avoids a very significant amount of buffer manager traffic and
      contention when scanning hash indexes, because it's no longer
      necessary to lock and pin the metapage for every scan.  We do need
      some way of figuring out when the cache is too stale to use any more,
      so that when we lock the primary bucket page to which the cached
      metapage points us, we can tell whether a split has occurred since we
      cached the metapage data.  To do that, we use the hash_prevblkno field
      in the primary bucket page, which would otherwise always be set to
      InvalidBuffer.
      
      This patch contains code so that it will continue working (although
      less efficiently) with hash indexes built before this change, but
      perhaps we should consider bumping the hash version and ripping out
      the compatibility code.  That decision can be made later, though.
      
      Mithun Cy, reviewed by Jesper Pedersen, Amit Kapila, and by me.
      Before committing, I made a number of cosmetic changes to the last
      posted version of the patch, adjusted _hash_getcachedmetap to be more
      careful about order of operation, and made some necessary updates to
      the pageinspect documentation and regression tests.
      293e24e5
  17. Feb 06, 2017
  18. Feb 03, 2017
    • Robert Haas's avatar
      pageinspect: More type-sanity surgery on the new hash index code. · 871ec0e3
      Robert Haas authored
      Uniformly expose unsigned quantities using the next-wider signed
      integer type (since we have no unsigned types at the SQL level).
      At the SQL level, this results a change to report itemoffset as
      int4 rather than int2.  Also at the SQL level, report one value
      that is an OID as type oid.  Under the hood, uniformly use macros
      that match the SQL output type as to both width and signedness.
      871ec0e3
    • Robert Haas's avatar
      pgstattuple: Add pgstathashindex. · e759854a
      Robert Haas authored
      Since pgstattuple v1.5 hasn't been released yet, no need for a new
      extension version.  The new function exposes statistics about hash
      indexes similar to what other pgstatindex functions return for other
      index types.
      
      Ashutosh Sharma, reviewed by Kuntal Ghosh.  Substantial further
      revisions by me.
      e759854a
    • Tom Lane's avatar
      In pageinspect/hashfuncs.c, avoid crashes on alignment-picky machines. · 14e9b18f
      Tom Lane authored
      On machines with MAXALIGN = 8, the payload of a bytea is not maxaligned,
      since it will start 4 bytes into a palloc'd value.  On alignment-picky
      hardware, this will cause failures in accesses to 8-byte-wide values
      within the page.  We already encountered this problem when we introduced
      GIN index inspection functions, and fixed it in commit 84ad68d6.  Make
      use of the same function for hash indexes.
      
      A small difficulty is that up to now contrib/pageinspect has not shared
      any functions at all across files.  To support that, introduce a common
      header file "pageinspect.h" for the module.
      
      Also, move get_page_from_raw() out of ginfuncs.c, where it didn't
      especially belong, and put it in rawpage.c which seems a more natural home.
      
      Per buildfarm.
      
      Discussion: https://postgr.es/m/17311.1486134714@sss.pgh.pa.us
      14e9b18f
    • Robert Haas's avatar
      pageinspect: Remove platform-dependent values from hash tests. · 29e312bc
      Robert Haas authored
      Per a report from Tom Lane, the ffactor reported by hash_metapage_info
      and the free_size reported by hash_page_stats vary by platform.
      
      Ashutosh Sharma and Robert Haas
      29e312bc
    • Tom Lane's avatar
      Fix a bunch more portability bugs in commit 08bf6e52. · c6eeb67d
      Tom Lane authored
      It seems like somebody used a dartboard while choosing integer widths
      for the various values taken and returned by these functions ... and
      then threw a fresh set of darts while writing the SQL declarations.
      
      This patch brings the C code into line with what the SQL declarations
      say, which is enough to make it not dump core on the particular 32-bit
      machine I'm testing on.  But I think we could do with another round
      of looking at what the datum widths *should* be.  For instance, it's
      not all that sensible that hash_bitmap_info decided to use int64 to
      represent a BlockNumber input when get_raw_page doesn't do it that way.
      
      There's also a remaining problem that the expected outputs from the
      test script are platform-dependent, but I'll leave that issue for
      somebody else.
      
      Per buildfarm.
      c6eeb67d
    • Robert Haas's avatar
      pageinspect: Try to fix some bugs in previous commit. · ed807fda
      Robert Haas authored
      Commit 08bf6e52 seems not to have
      used the correct *GetDatum and PG_GETARG_* macros for the SQL types
      in some cases, and some of the SQL types seem to have been poorly
      chosen, too.  Try to fix it.  I'm not sure if this is the reason
      why the buildfarm is currently unhappy with this code, but it
      seems like a good place to start.
      
      Buildfarm unhappiness reported by Tom Lane.
      ed807fda
  19. Feb 02, 2017
  20. Feb 01, 2017
    • Heikki Linnakangas's avatar
      Replace isMD5() with a more future-proof way to check if pw is encrypted. · dbd69118
      Heikki Linnakangas authored
      The rule is that if pg_authid.rolpassword begins with "md5" and has the
      right length, it's an MD5 hash, otherwise it's a plaintext password. The
      idiom has been to use isMD5() to check for that, but that gets awkward,
      when we add new kinds of verifiers, like the verifiers for SCRAM
      authentication in the pending SCRAM patch set. Replace isMD5() with a new
      get_password_type() function, so that when new verifier types are added, we
      don't need to remember to modify every place that currently calls isMD5(),
      to also recognize the new kinds of verifiers.
      
      Also, use the new plain_crypt_verify function in passwordcheck, so that it
      doesn't need to know about MD5, or in the future, about other kinds of
      hashes or password verifiers.
      
      Reviewed by Michael Paquier and Peter Eisentraut.
      
      Discussion: https://www.postgresql.org/message-id/2d07165c-1793-e243-a2a9-e45b624c7580@iki.fi
      dbd69118
Loading