postgresql/src/backend
Tom Lane 8004953b5a Speed up ruleutils' name de-duplication code, and fix overlength-name case.
Since commit 11e131854f, ruleutils.c has
attempted to ensure that each RTE in a query or plan tree has a unique
alias name.  However, the code that was added for this could be quite slow,
even as bad as O(N^3) if N identical RTE names must be replaced, as noted
by Jeff Janes.  Improve matters by building a transient hash table within
set_rtable_names.  The hash table in itself reduces the cost of detecting a
duplicate from O(N) to O(1), and we can save another factor of N by storing
the number of de-duplicated names already created for each entry, so that
we don't have to re-try names already created.  This way is probably a bit
slower overall for small range tables, but almost by definition, such cases
should not be a performance problem.

In principle the same problem applies to the column-name-de-duplication
code; but in practice that seems to be less of a problem, first because
N is limited since we don't support extremely wide tables, and second
because duplicate column names within an RTE are fairly rare, so that in
practice the cost is more like O(N^2) not O(N^3).  It would be very much
messier to fix the column-name code, so for now I've left that alone.

An independent problem in the same area was that the de-duplication code
paid no attention to the identifier length limit, and would happily produce
identifiers that were longer than NAMEDATALEN and wouldn't be unique after
truncation to NAMEDATALEN.  This could result in dump/reload failures, or
perhaps even views that silently behaved differently than before.  We can
fix that by shortening the base name as needed.  Fix it for both the
relation and column name cases.

In passing, check for interrupts in set_rtable_names, just in case it's
still slow enough to be an issue.

Back-patch to 9.3 where this code was introduced.
2015-11-16 13:45:17 -05:00
..
access Move each SLRU's lwlocks to a separate tranche. 2015-11-12 14:59:09 -05:00
bootstrap pgindent run for 9.5 2015-05-23 21:35:49 -04:00
catalog Message style improvements 2015-10-28 20:38:36 -04:00
commands Move each SLRU's lwlocks to a separate tranche. 2015-11-12 14:59:09 -05:00
executor Remove accidentally-committed debugging code. 2015-11-15 18:07:57 -05:00
foreign Code review for foreign/custom join pushdown patch. 2015-05-10 14:36:36 -04:00
lib Avoid use of float arithmetic in bipartite_match.c. 2015-08-23 13:02:18 -04:00
libpq Make idle backends exit if the postmaster dies. 2015-11-12 09:00:33 -05:00
main Revoke support for strxfrm() that write past the specified array length. 2015-07-08 20:44:21 -04:00
nodes Provide readfuncs support for custom scans. 2015-11-12 07:40:31 -05:00
optimizer Generate parallel sequential scan plans in simple cases. 2015-11-11 09:02:52 -05:00
parser Message style improvements 2015-10-28 20:38:36 -04:00
po Translation updates 2015-06-28 23:56:55 -04:00
port On Windows, ensure shared memory handle gets closed if not being used. 2015-10-13 11:21:33 -04:00
postmaster Pass extra data to bgworkers, and use this to fix parallel contexts. 2015-11-05 12:13:56 -05:00
regex Fix enforcement of restrictions inside regexp lookaround constraints. 2015-11-07 12:43:24 -05:00
replication Set replication origin when decoding commit records. 2015-11-09 00:03:35 +01:00
rewrite Apply SELECT policies in INSERT/UPDATE+RETURNING 2015-10-05 07:55:13 -04:00
snowball Remove no-longer-required function declarations. 2015-05-24 12:20:23 -04:00
storage Move each SLRU's lwlocks to a separate tranche. 2015-11-12 14:59:09 -05:00
tcop Fix problems with ParamListInfo serialization mechanism. 2015-11-02 18:11:29 -05:00
tsearch pgindent run for 9.5 2015-05-23 21:35:49 -04:00
utils Speed up ruleutils' name de-duplication code, and fix overlength-name case. 2015-11-16 13:45:17 -05:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Remove maintainer-check target, fold into normal build 2013-10-10 20:11:56 -04:00
Makefile Revert "Have dtrace depend on object files directly, not objfiles.txt" 2015-10-15 13:16:03 -04:00
nls.mk Remove trailing slashes from directories in find command 2015-09-18 22:06:54 -04:00