1. 07 Mar, 2015 3 commits
    • Noah Misch's avatar
      Build fls.o only when AC_REPLACE_FUNCS so dictates via $(LIBOBJS). · 9d265ae7
      Noah Misch authored
      By building it unconditionally, libpgport inadvertently replaced any
      libc version of the function.  This is essentially a code cleanup; any
      effect on performance is almost surely too small to notice.
      9d265ae7
    • Noah Misch's avatar
      Add CHECK_FOR_INTERRUPTS() to the wait_pid() loop. · 93751570
      Noah Misch authored
      Though the one contemporary caller uses it in a limited way, this
      function could loop indefinitely if pointed to an arbitrary PID.
      93751570
    • Peter Eisentraut's avatar
      Remove rolcatupdate · bb8582ab
      Peter Eisentraut authored
      This role attribute is an ancient PostgreSQL feature, but could only be
      set by directly updating the system catalogs, and it doesn't have any
      clearly defined use.
      
      Author: Adam Brightwell <adam.brightwell@crunchydatasolutions.com>
      bb8582ab
  2. 06 Mar, 2015 3 commits
    • Alvaro Herrera's avatar
      Add some more tests on event triggers · 6510c832
      Alvaro Herrera authored
      Fabien Coelho
      Reviewed by Robert Haas
      6510c832
    • Tom Lane's avatar
      Rethink function argument sorting in pg_dump. · e3bfe6d8
      Tom Lane authored
      Commit 7b583b20 created an unnecessary
      dump failure hazard by applying pg_get_function_identity_arguments()
      to every function in the database, even those that won't get dumped.
      This could result in snapshot-related problems if concurrent sessions are,
      for example, creating and dropping temporary functions, as noted by Marko
      Tiikkaja in bug #12832.  While this is by no means pg_dump's only such
      issue with concurrent DDL, it's unfortunate that we added a new failure
      mode for cases that used to work, and even more so that the failure was
      created for basically cosmetic reasons (ie, to sort overloaded functions
      more deterministically).
      
      To fix, revert that patch and instead sort function arguments using
      information that pg_dump has available anyway, namely the names of the
      argument types.  This will produce a slightly different sort ordering for
      overloaded functions than the previous coding; but applying strcmp
      directly to the output of pg_get_function_identity_arguments really was
      a bit odd anyway.  The sorting will still be name-based and hence
      independent of possibly-installation-specific OID assignments.  A small
      additional benefit is that sorting now works regardless of server version.
      
      Back-patch to 9.3, where the previous commit appeared.
      e3bfe6d8
    • Alvaro Herrera's avatar
      Fix contrib/file_fdw's expected file · c6ee39bc
      Alvaro Herrera authored
      I forgot to update it on yesterday's cf34e373.
      c6ee39bc
  3. 05 Mar, 2015 7 commits
    • Alvaro Herrera's avatar
      Fix user mapping object description · cf34e373
      Alvaro Herrera authored
      We were using "user mapping for user XYZ" as description for user mappings, but
      that's ambiguous because users can have mappings on multiple foreign
      servers; therefore change it to "for user XYZ on server UVW" instead.
      Object identities for user mappings are also updated in the same way, in
      branches 9.3 and above.
      
      The incomplete description string was introduced together with the whole
      SQL/MED infrastructure by commit cae565e5 of 8.4 era, so backpatch all
      the way back.
      cf34e373
    • Alvaro Herrera's avatar
      Silence warning in non-assert-enabled build · bf22d270
      Alvaro Herrera authored
      An OID return value was being used only for a (rather pointless) assert.
      Silence by removing the variable and the assert.
      
      Per note from Peter Geoghegan
      bf22d270
    • Tom Lane's avatar
      Remove comment claiming that PARAM_EXTERN Params always have typmod -1. · 3200b15b
      Tom Lane authored
      This hasn't been true in quite some time, cf plpgsql's make_datum_param().
      3200b15b
    • Fujii Masao's avatar
      Fix typo in comment. · 934d1226
      Fujii Masao authored
      934d1226
    • Tom Lane's avatar
      Avoid unused-variable warning in non-assert builds. · a5c29d37
      Tom Lane authored
      Oversight in my commit b9896198.
      a5c29d37
    • Tom Lane's avatar
      Change plpgsql's cast cache to consider source typmod as significant. · 7f3014dc
      Tom Lane authored
      I had thought that there was no need to maintain separate cache entries
      for different source typmods, but further experimentation shows that there
      is an advantage to doing so in some cases.  In particular, if a domain has
      a typmod (say, "CREATE DOMAIN d AS numeric(20,0)"), failing to notice the
      source typmod leads to applying a length-coercion step even when the
      source has the correct typmod.
      7f3014dc
    • Tom Lane's avatar
      Need to special-case RECORD as well as UNKNOWN in plpgsql's casting logic. · 45f2c2fc
      Tom Lane authored
      This is because can_coerce_type thinks that RECORD can be cast to any
      composite type, but coerce_record_to_complex only works for inputs that are
      RowExprs or whole-row Vars, so we get a hard failure on a CaseTestExpr.
      
      Perhaps these corner cases ought to be fixed so that coerce_to_target_type
      actually returns NULL as per its specification, rather than failing ...
      but for the moment an extra check here is the path of least resistance.
      45f2c2fc
  4. 04 Mar, 2015 4 commits
    • Tom Lane's avatar
      Use standard casting mechanism to convert types in plpgsql, when possible. · 1345cc67
      Tom Lane authored
      plpgsql's historical method for converting datatypes during assignments was
      to apply the source type's output function and then the destination type's
      input function.  Aside from being miserably inefficient in most cases, this
      method failed outright in many cases where a user might expect it to work;
      an example is that "declare x int; ... x := 3.9;" would fail, not round the
      value to 4.
      
      Instead, let's convert by applying the appropriate assignment cast whenever
      there is one.  To avoid breaking compatibility unnecessarily, fall back to
      the I/O conversion method if there is no assignment cast.
      
      So far as I can tell, there is just one case where this method produces a
      different result than the old code in a case where the old code would not
      have thrown an error.  That is assignment of a boolean value to a string
      variable (type text, varchar, or bpchar); the old way gave boolean's output
      representation, ie 't'/'f', while the new way follows the behavior of the
      bool-to-text cast and so gives 'true' or 'false'.  This will need to be
      called out as an incompatibility in the 9.5 release notes.
      
      Aside from handling many conversion cases more sanely, this method is
      often significantly faster than the old way.  In part that's because
      of more effective caching of the conversion info.
      1345cc67
    • Tom Lane's avatar
      Fix cost estimation for indexscans on expensive indexed expressions. · b9896198
      Tom Lane authored
      genericcostestimate() and friends used the cost of the entire indexqual
      expressions as the charge for initial evaluation of indexscan arguments.
      But of course the index column is not evaluated, only the other side
      of the qual expression, so this was a bad overestimate if the index
      column was an expensive expression.
      
      To fix, refactor the logic in this area so that there's a single routine
      charged with deconstructing index quals and figuring out what is the index
      column and what is the comparison expression.  This is more or less free in
      the case of btree indexes, since btcostestimate() was doing equivalent
      deconstruction already.  It probably adds a bit of new overhead in the cases
      of other index types, but not a lot.  (In the case of GIN I think I saved
      something by getting rid of code that wasn't aware that the index column
      associations were already available "for free".)
      
      Per recent gripe from Jeff Janes.
      
      Arguably this is a bug fix, but I'm hesitant to back-patch because of the
      possibility of destabilizing plan choices that people may be happy with.
      b9896198
    • Fujii Masao's avatar
      Fix an obsolete reference to SnapshotNow in comment. · f8b031bc
      Fujii Masao authored
      Peter Geoghegan
      f8b031bc
    • Tom Lane's avatar
      Fix long-obsolete code for separating filter conditions in cost_index(). · 497bac7d
      Tom Lane authored
      This code relied on pointer equality to identify which restriction clauses
      also appear in the indexquals (and, therefore, don't need to be applied as
      simple filter conditions).  That was okay once upon a time, years ago,
      before we introduced the equivalence-class machinery.  Now there's about a
      50-50 chance that an equality clause appearing in the indexquals will be
      the mirror image (commutator) of its mate in the restriction list.  When
      that happens, we'd erroneously think that the clause would be re-evaluated
      at each visited row, and therefore inflate the cost estimate for the
      indexscan by the clause's cost.
      
      Add some logic to catch this case.  It seems to me that it continues not to
      be worthwhile to expend the extra predicate-proof work that createplan.c
      will do on the finally-selected plan, but this case is common enough and
      cheap enough to handle that we should do so.
      
      This will make a small difference (about one cpu_operator_cost per row)
      in simple cases; but in situations where there's an expensive function in
      the indexquals, it can make a very large difference, as seen in recent
      example from Jeff Janes.
      
      This is a long-standing bug, but I'm hesitant to back-patch because of the
      possibility of destabilizing plan choices that people may be happy with.
      497bac7d
  5. 03 Mar, 2015 6 commits
    • Robert Haas's avatar
      Remove residual NULL-pstate handling in addRangeTableEntry. · 5223ddac
      Robert Haas authored
      Passing a NULL pstate wouldn't actually work, because isLockedRefname()
      isn't prepared to cope with it; and there hasn't been any in-core code
      that tries in over a decade.  So just remove the residual NULL handling.
      
      Spotted by Coverity; analysis and patch by Michael Paquier.
      5223ddac
    • Alvaro Herrera's avatar
      Change many routines to return ObjectAddress rather than OID · a2e35b53
      Alvaro Herrera authored
      The changed routines are mostly those that can be directly called by
      ProcessUtilitySlow; the intention is to make the affected object
      information more precise, in support for future event trigger changes.
      Originally it was envisioned that the OID of the affected object would
      be enough, and in most cases that is correct, but upon actually
      implementing the event trigger changes it turned out that ObjectAddress
      is more widely useful.
      
      Additionally, some command execution routines grew an output argument
      that's an object address which provides further info about the executed
      command.  To wit:
      
      * for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
        the new constraint
      
      * for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
        schema that originally contained the object.
      
      * for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
        of the object added to or dropped from the extension.
      
      There's no user-visible change in this commit, and no functional change
      either.
      
      Discussion: 20150218213255.GC6717@tamriel.snowman.net
      Reviewed-By: Stephen Frost, Andres Freund
      a2e35b53
    • Alvaro Herrera's avatar
      Add comment for "is_internal" parameter · 6f9d7990
      Alvaro Herrera authored
      This was missed in my commit f4c4335a of 9.3 vintage, so backpatch to
      that.
      6f9d7990
    • Tom Lane's avatar
      Reduce json <=> jsonb casts from explicit-only to assignment level. · b67f1ce1
      Tom Lane authored
      There's no reason to make users write an explicit cast to store a
      json value in a jsonb column or vice versa.
      
      We could probably even make these implicit, but that might open us up
      to problems with ambiguous function calls, so for now just do this.
      b67f1ce1
    • Robert Haas's avatar
      pgbench: Fix mistakes in Makefile. · e5f36902
      Robert Haas authored
      My commit 878fdcb8 was not quite
      right.  Tom Lane pointed out one of the mistakes fixed here, and I
      noticed the other myself while reviewing what I'd committed.
      e5f36902
    • Tom Lane's avatar
      Fix busted markup. · d1479011
      Tom Lane authored
      Evidently from commit 878fdcb8.
      Per buildfarm.
      d1479011
  6. 02 Mar, 2015 2 commits
    • Robert Haas's avatar
      pgbench: Add a real expression syntax to \set · 878fdcb8
      Robert Haas authored
      Previously, you could do \set variable operand1 operator operand2, but
      nothing more complicated.  Now, you can \set variable expression, which
      makes it much simpler to do multi-step calculations here.  This also
      adds support for the modulo operator (%), with the same semantics as in
      C.
      
      Robert Haas and Fabien Coelho, reviewed by Álvaro Herrera and
      Stephen Frost
      878fdcb8
    • Stephen Frost's avatar
      Fix pg_dump handling of extension config tables · ebd092bc
      Stephen Frost authored
      Since 9.1, we've provided extensions with a way to denote
      "configuration" tables- tables created by an extension which the user
      may modify.  By marking these as "configuration" tables, the extension
      is asking for the data in these tables to be pg_dump'd (tables which
      are not marked in this way are assumed to be entirely handled during
      CREATE EXTENSION and are not included at all in a pg_dump).
      
      Unfortunately, pg_dump neglected to consider foreign key relationships
      between extension configuration tables and therefore could end up
      trying to reload the data in an order which would cause FK violations.
      
      This patch teaches pg_dump about these dependencies, so that the data
      dumped out is done so in the best order possible.  Note that there's no
      way to handle circular dependencies, but those have yet to be seen in
      the wild.
      
      The release notes for this should include a caution to users that
      existing pg_dump-based backups may be invalid due to this issue.  The
      data is all there, but restoring from it will require extracting the
      data for the configuration tables and then loading them in the correct
      order by hand.
      
      Discussed initially back in bug #6738, more recently brought up by
      Gilles Darold, who provided an initial patch which was further reworked
      by Michael Paquier.  Further modifications and documentation updates
      by me.
      
      Back-patch to 9.1 where we added the concept of extension configuration
      tables.
      ebd092bc
  7. 01 Mar, 2015 6 commits
    • Stephen Frost's avatar
      Fix targetRelation initializiation in prepsecurity · ee4ddcb3
      Stephen Frost authored
      In 6f9bd50e, we modified
      expand_security_quals() to tell expand_security_qual() about when the
      current RTE was the targetRelation.  Unfortunately, that commit
      initialized the targetRelation variable used outside of the loop over
      the RTEs instead of at the start of it.
      
      This patch moves the variable and the initialization of it into the
      loop, where it should have been to begin with.
      
      Pointed out by Dean Rasheed.
      
      Back-patch to 9.4 as the original commit was.
      ee4ddcb3
    • Tom Lane's avatar
      Use the typcache to cache constraints for domain types. · 8abb3cda
      Tom Lane authored
      Previously, we cached domain constraints for the life of a query, or
      really for the life of the FmgrInfo struct that was used to invoke
      domain_in() or domain_check().  But plpgsql (and probably other places)
      are set up to cache such FmgrInfos for the whole lifespan of a session,
      which meant they could be enforcing really stale sets of constraints.
      On the other hand, searching pg_constraint once per query gets kind of
      expensive too: testing says that as much as half the runtime of a
      trivial query such as "SELECT 0::domaintype" went into that.
      
      To fix this, delegate the responsibility for tracking a domain's
      constraints to the typcache, which has the infrastructure needed to
      detect syscache invalidation events that signal possible changes.
      This not only removes unnecessary repeat reads of pg_constraint,
      but ensures that we never apply stale constraint data: whatever we
      use is the current data according to syscache rules.
      
      Unfortunately, the current configuration of the system catalogs means
      we have to flush cached domain-constraint data whenever either pg_type
      or pg_constraint changes, which happens rather a lot (eg, creation or
      deletion of a temp table will do it).  It might be worth rearranging
      things to split pg_constraint into two catalogs, of which the domain
      constraint one would probably be very low-traffic.  That's a job for
      another patch though, and in any case this patch should improve matters
      materially even with that handicap.
      
      This patch makes use of the recently-added memory context reset callback
      feature to manage the lifespan of domain constraint caches, so that we
      don't risk deleting a cache that might be in the midst of evaluation.
      
      Although this is a bug fix as well as a performance improvement, no
      back-patch.  There haven't been many if any field complaints about
      stale domain constraint checks, so it doesn't seem worth taking the
      risk of modifying data structures as basic as MemoryContexts in back
      branches.
      8abb3cda
    • Noah Misch's avatar
      Add transform functions for AT TIME ZONE. · b8a18ad4
      Noah Misch authored
      This makes "ALTER TABLE tabname ALTER tscol TYPE ... USING tscol AT TIME
      ZONE 'UTC'" skip rewriting the table when altering from "timestamp" to
      "timestamptz" or vice versa.  While it would be nicer still to optimize
      this in the absence of the USING clause given timezone==UTC, transform
      functions must consult IMMUTABLE facts only.
      b8a18ad4
    • Noah Misch's avatar
      Unlink static libraries before rebuilding them. · 424793fa
      Noah Misch authored
      When the library already exists in the build directory, "ar" preserves
      members not named on its command line.  This mattered when, for example,
      a "configure" rerun dropped a file from $(LIBOBJS).  libpgport carried
      the obsolete member until "make clean".  Back-patch to 9.0 (all
      supported versions).
      424793fa
    • Tom Lane's avatar
      Move memory context callback declarations into palloc.h. · 097fe194
      Tom Lane authored
      Initial experience with this feature suggests that instances of
      MemoryContextCallback are likely to propagate into some widely-used headers
      over time.  As things stood, that would result in pulling memutils.h or
      at least memnodes.h into common headers, which does not seem desirable.
      Instead, let's decide that this feature is part of the "ordinary palloc
      user" API rather than the "specialized context management" API, and as
      such should be declared in palloc.h not memutils.h.
      097fe194
    • Alvaro Herrera's avatar
      Fix intermittent failure in event_trigger test · e059e02e
      Alvaro Herrera authored
      As evidenced by measles in buildfarm.  Pointed out by Tom.
      e059e02e
  8. 28 Feb, 2015 3 commits
    • Tom Lane's avatar
      Track typmods in plpgsql expression evaluation and assignment. · e524cbdc
      Tom Lane authored
      The main value of this change is to avoid expensive I/O conversions when
      assigning to a variable that has a typmod specification, if the value
      to be assigned is already known to have the right typmod.  This is
      particularly valuable for arrays with typmod specifications; formerly,
      in an assignment to an array element the entire array would invariably
      get put through double I/O conversion to check the typmod, to absolutely
      no purpose since we'd already properly coerced the new element value.
      
      Extracted from my "expanded arrays" patch; this seems worth committing
      separately, whatever becomes of that patch, since it's really an
      independent issue.
      
      As long as we're changing the function signatures, take the opportunity
      to rationalize the argument lists of exec_assign_value, exec_cast_value,
      and exec_simple_cast_value; that is, put the arguments into a saner order,
      and get rid of the bizarre choice to pass exec_assign_value's isNull flag
      by reference.
      e524cbdc
    • Tom Lane's avatar
      Fix planning of star-schema-style queries. · b514a746
      Tom Lane authored
      Part of the intent of the parameterized-path mechanism was to handle
      star-schema queries efficiently, but some overly-restrictive search
      limiting logic added in commit e2fa76d8
      prevented such cases from working as desired.  Fix that and add a
      regression test about it.  Per gripe from Marc Cousin.
      
      This is arguably a bug rather than a new feature, so back-patch to 9.2
      where parameterized paths were introduced.
      b514a746
    • Tom Lane's avatar
      Improve mmgr README. · c4f4c7ca
      Tom Lane authored
      Add documentation about the new reset callback mechanism.
      
      Also, at long last, recast the existing text so that it describes the
      current context mechanisms as established fact rather than something
      we're going to implement.  Shoulda done that in 2001 or so ...
      c4f4c7ca
  9. 27 Feb, 2015 6 commits
    • Tom Lane's avatar
      Suppress uninitialized-variable warning from less-bright compilers. · d61f1a93
      Tom Lane authored
      The type variable must get set on first iteration of the while loop,
      but there are reasonably modern gcc versions that don't realize that.
      Initialize it with a dummy value.  This undoes a removal of initialization
      in commit 654809e7.
      d61f1a93
    • Tom Lane's avatar
      Redefine MemoryContextReset() as deleting, not resetting, child contexts. · eaa5808e
      Tom Lane authored
      That is, MemoryContextReset() now means what was formerly meant by
      MemoryContextResetAndDeleteChildren(), and the latter is now just a macro
      alias for the former.  If you really want the functionality that was
      formerly provided by MemoryContextReset(), what you have to do is
      MemoryContextResetChildren() plus MemoryContextResetOnly() (which is a
      new API to reset *only* the named context and not touch its children).
      
      The reason for this change is that near fifteen years of experience has
      proven that there is noplace where old-style MemoryContextReset() is
      actually what you want.  Making that the default behavior has led to lots
      of context-leakage bugs, while we've not found anyplace where it's actually
      necessary to keep the child contexts; at least the standard regression
      tests do not reveal anyplace where this change breaks anything.  And there
      are upcoming patches that will introduce additional reasons why child
      contexts need to be removed.
      
      We could change existing calls of MemoryContextResetAndDeleteChildren to be
      just MemoryContextReset, but for the moment I'll leave them alone; they're
      not costing anything.
      eaa5808e
    • Alvaro Herrera's avatar
      Make CREATE OR REPLACE VIEW internally more consistent · fbef4342
      Alvaro Herrera authored
      The way that columns are added to a view is by calling
      AlterTableInternal with special subtype AT_AddColumnToView; but that
      subtype is changed to AT_AddColumnRecurse by ATPrepAddColumn.  This has
      no visible effect in the current code, since views cannot have
      inheritance children (thus the recursion step is a no-op) and adding a
      column to a view is executed identically to doing it to a table; but it
      does make a difference for future event trigger code keeping track of
      commands, because the current situation leads to confusing the case with
      a normal ALTER TABLE ADD COLUMN.
      
      Fix the problem by passing a flag to ATPrepAddColumn to prevent it from
      changing the command subtype.  The event trigger code can then properly
      ignore the subcommand.  (We could remove the call to ATPrepAddColumn,
      since views are never typed, and there is never a need for recursion,
      which are the two conditions that are checked by ATPrepAddColumn; but it
      seems more future-proof to keep the call in place.)
      fbef4342
    • Tom Lane's avatar
      Invent a memory context reset/delete callback mechanism. · f65e8270
      Tom Lane authored
      This allows cleanup actions to be registered to be called just before a
      particular memory context's contents are flushed (either by deletion or
      MemoryContextReset).  The patch in itself has no use-cases for this, but
      several likely reasons for wanting this exist.
      
      In passing, per discussion, rearrange some boolean fields in struct
      MemoryContextData so as to avoid wasted padding space.  For safety,
      this requires making allowInCritSection's existence unconditional;
      but I think that's a better approach than what was there anyway.
      f65e8270
    • Alvaro Herrera's avatar
      Fix a couple of trivial issues in jsonb.c · 654809e7
      Alvaro Herrera authored
      Typo "aggreagate" appeared three times, and the return value of function
      JsonbIteratorNext() was being assigned to an int variable in a bunch of
      places.
      654809e7
    • Alvaro Herrera's avatar
      Fix table_rewrite event trigger for ALTER TYPE/SET DATA TYPE CASCADE · 3f190f67
      Alvaro Herrera authored
      When a composite type being used in a typed table is modified by way
      of ALTER TYPE, a table rewrite occurs appearing to come from ALTER TYPE.
      The existing event_trigger.c code was unable to cope with that
      and raised a spurious error.  The fix is just to accept that command
      tag for the event, and document this properly.
      
      Noted while fooling with deparsing of DDL commands.  This appears to be
      an oversight in commit 618c9430.
      
      Thanks to Mark Wong for documentation wording help.
      3f190f67