Commit Graph

549 Commits

Author SHA1 Message Date
Tom Lane 7863404417 A bunch of changes aimed at reducing backend startup time...
Improve 'pg_internal.init' relcache entry preload mechanism so that it is
safe to use for all system catalogs, and arrange to preload a realistic
set of system-catalog entries instead of only the three nailed-in-cache
indexes that were formerly loaded this way.  Fix mechanism for deleting
out-of-date pg_internal.init files: this must be synchronized with transaction
commit, not just done at random times within transactions.  Drive it off
relcache invalidation mechanism so that no special-case tests are needed.

Cache additional information in relcache entries for indexes (their pg_index
tuples and index-operator OIDs) to eliminate repeated lookups.  Also cache
index opclass info at the per-opclass level to avoid repeated lookups during
relcache load.

Generalize 'systable scan' utilities originally developed by Hiroshi,
move them into genam.c, use in a number of places where there was formerly
ugly code for choosing either heap or index scan.  In particular this allows
simplification of the logic that prevents infinite recursion between syscache
and relcache during startup: we can easily switch to heapscans in relcache.c
when and where needed to avoid recursion, so IndexScanOK becomes simpler and
does not need any expensive initialization.

Eliminate useless opening of a heapscan data structure while doing an indexscan
(this saves an mdnblocks call and thus at least one kernel call).
2002-02-19 20:11:20 +00:00
Tom Lane f7fb29dec3 Shouldn't try to copy null datums with datumCopy. 2002-01-03 18:01:59 +00:00
Tom Lane 63cc56de54 Suppress subquery pullup and pushdown when the subquery has any
set-returning functions in its target list.  This ensures that we
won't rewrite the query in a way that places set-returning functions
into quals (WHERE clauses).  Cf. bug reports from Joe Conway.
2001-12-10 22:54:12 +00:00
Tom Lane c31bcbc8d6 Repair failure to mark an inserted Materialize node with the appropriate
extParam/locParam lists.  Per bug #526.
2001-11-30 19:24:15 +00:00
Tom Lane e433bf5a5e If the inputs of a UNION/INTERSECT/EXCEPT construct all agree on the
typmod of a particular column, mark the output with that same typmod,
not -1 as formerly.  -1 is still used if there is any disagreement.
Part of response to bug#513.
2001-11-12 20:04:20 +00:00
Tom Lane c5c97318f9 In find_mergeclauses_for_pathkeys, it's okay to return multiple merge
clauses per path key.  Indeed, we *must* do so or we will be unable to
form a valid plan for FULL JOIN with overlapping join conditions, eg
select * from a full join b on
a.v1 = b.v1 and a.v2 = b.v2 and a.v1 = b.v2.
2001-11-11 20:33:53 +00:00
Tom Lane ad511a3ff3 sort_inner_and_outer needs a check to ensure that it's consumed all the
mergeclauses in RIGHT/FULL join cases, just like the other routines have.
I'm not quite sure why I thought it didn't need one --- but Nick
Fankhauser's recent bug report proves that it does.
2001-11-11 19:18:54 +00:00
Bruce Momjian ea08e6cd55 New pgindent run with fixes suggested by Tom. Patch manually reviewed,
initdb/regression tests pass.
2001-11-05 17:46:40 +00:00
Tom Lane 9685afb0b2 Add default expressions to INSERTs during planning, not during parse
analysis.  This keeps stored rules from prematurely absorbing default
information, which is necessary for ALTER TABLE SET DEFAULT to work
unsurprisingly with rules.  See pgsql-bugs discussion 24-Oct-01.
2001-11-02 20:23:02 +00:00
Tom Lane 96ca8ffebc Fix problems with subselects used in GROUP BY expressions, per gripe
from Philip Warner.  Side effect of change is that GROUP BY expressions
will not be re-evaluated at multiple plan levels anymore, whereas this
sometimes happened with old code.
2001-10-30 19:58:58 +00:00
Bruce Momjian c41b6b1b9c Fix small problem Tom Lane found with pgindent run. 2001-10-30 05:38:56 +00:00
Bruce Momjian 6783b2372e Another pgindent run. Fixes enum indenting, and improves #endif
spacing.  Also adds space for one-line comments.
2001-10-28 06:26:15 +00:00
Bruce Momjian b81844b173 pgindent run on all C files. Java run to follow. initdb/regression
tests pass.
2001-10-25 05:50:21 +00:00
Tom Lane 6254465d06 Extend code that deduces implied equality clauses to detect whether a
clause being added to a particular restriction-clause list is redundant
with those already in the list.  This avoids useless work at runtime,
and (perhaps more importantly) keeps the selectivity estimation routines
from generating too-small estimates of numbers of output rows.
Also some minor improvements in OPTIMIZER_DEBUG displays.
2001-10-18 16:11:42 +00:00
Tom Lane 6f33c179b9 Produce slightly saner-looking EXPLAIN output for a Result node. 2001-09-21 04:06:04 +00:00
Tom Lane 6c91eef7b7 Fix handling of pg_type.typdefault per bug report from Dave Blasby.
If there's anyone out there who's actually using datatype-defined
default values, this will be an incompatible change in behavior ...
but the old behavior was so broken that I doubt anyone was using it.
2001-09-06 02:07:42 +00:00
Tom Lane f933766ba7 Restructure pg_opclass, pg_amop, and pg_amproc per previous discussions in
pgsql-hackers.  pg_opclass now has a row for each opclass supported by each
index AM, not a row for each opclass name.  This allows pg_opclass to show
directly whether an AM supports an opclass, and furthermore makes it possible
to store additional information about an opclass that might be AM-dependent.
pg_opclass and pg_amop now store "lossy" and "haskeytype" information that we
previously expected the user to remember to provide in CREATE INDEX commands.
Lossiness is no longer an index-level property, but is associated with the
use of a particular operator in a particular index opclass.

Along the way, IndexSupportInitialize now uses the syscaches to retrieve
pg_amop and pg_amproc entries.  I find this reduces backend launch time by
about ten percent, at the cost of a couple more special cases in catcache.c's
IndexScanOK.

Initial work by Oleg Bartunov and Teodor Sigaev, further hacking by Tom Lane.

initdb forced.
2001-08-21 16:36:06 +00:00
Tom Lane 4bc9f5e9ba Fix brokenness of nested EXCEPT/INTERSECT queries. prepunion was being
a tad sloppy about generating the targetlist for some nodes, by generating
a tlist entry that claimed to be a constant when the value wasn't actually
constant.  This caused setrefs.c to do the wrong thing later on.
2001-08-14 17:12:57 +00:00
Tom Lane 246793469e Modify partial-index-predicate applicability tester to test whether
clauses are equal(), before trying to match them up using btree opclass
inference rules.  This allows it to recognize many simple cases involving
non-btree operations, for example 'x IS NULL'.  Clean up code a little.
2001-08-06 18:09:45 +00:00
Tom Lane 0889bd00bd Further thought shows that has_distinct_on_clause() needs to take much
more care with resjunk tlist entries than it was doing.  The original
coding ignored resjunk entries entirely, but a resjunk entry that is
in either the distinctClause or sortClause lists indicates that DISTINCT
ON was used.  It's important for ruleutils.c to get this right, else we
may dump views using DISTINCT ON incorrectly.
2001-07-31 20:16:33 +00:00
Tom Lane 421467cdc8 Fix optimizer to not try to push WHERE clauses down into a sub-SELECT that
has a DISTINCT ON clause, per bug report from Anthony Wood.  While at it,
improve the DISTINCT-ON-clause recognizer routine to not be fooled by out-
of-order DISTINCT lists.
2001-07-31 17:56:31 +00:00
Tom Lane 40db52af34 Do not push down quals into subqueries that have LIMIT/OFFSET clauses,
since the added qual could change the set of rows that get past the
LIMIT.  Per discussion on pgsql-sql 7/15/01.
2001-07-16 17:57:02 +00:00
Tom Lane f31dc0ada7 Partial indexes work again, courtesy of Martijn van Oosterhout.
Note: I didn't force an initdb, figuring that one today was enough.
However, there is a new function in pg_proc.h, and pg_dump won't be
able to dump partial indexes until you add that function.
2001-07-16 05:07:00 +00:00
Tom Lane c8076f09d2 Restructure index AM interface for index building and index tuple deletion,
per previous discussion on pghackers.  Most of the duplicate code in
different AMs' ambuild routines has been moved out to a common routine
in index.c; this means that all index types now do the right things about
inserting recently-dead tuples, etc.  (I also removed support for EXTEND
INDEX in the ambuild routines, since that's about to go away anyway, and
it cluttered the code a lot.)  The retail indextuple deletion routines have
been replaced by a "bulk delete" routine in which the indexscan is inside
the access method.  I haven't pushed this change as far as it should go yet,
but it should allow considerable simplification of the internal bookkeeping
for deletions.  Also, add flag columns to pg_am to eliminate various
hardcoded tests on AM OIDs, and remove unused pg_am columns.

Fix rtree and gist index types to not attempt to store NULLs; before this,
gist usually crashed, while rtree managed not to crash but computed wacko
bounding boxes for NULL entries (which might have had something to do with
the performance problems we've heard about occasionally).

Add AtEOXact routines to hash, rtree, and gist, all of which have static
state that needs to be reset after an error.  We discovered this need long
ago for btree, but missed the other guys.

Oh, one more thing: concurrent VACUUM is now the default.
2001-07-15 22:48:19 +00:00
Tom Lane 4d58a7ca87 Optimizer can now estimate selectivity of IS NULL, IS NOT NULL,
IS TRUE, etc, with some degree of verisimilitude.  Split out
selectivity support functions from builtins.h into a new header
file selfuncs.h, so as to reduce the number of header files builtins.h
must depend on.  Fix a few missing inclusions exposed thereby.
From Joe Conway, with some kibitzing from Tom Lane.
2001-06-25 21:11:45 +00:00
Tom Lane 116d2bba7e Add IS UNKNOWN, IS NOT UNKNOWN boolean tests, fix the existing boolean
tests to return the correct results per SQL9x when given NULL inputs.
Reimplement these tests as well as IS [NOT] NULL to have their own
expression node types, instead of depending on special functions.
From Joe Conway, with a little help from Tom Lane.
2001-06-19 22:39:12 +00:00
Tom Lane 1f1ca182be Make inet/cidr << and <<= operators indexable. From Alex Pilosov <alex@pilosoft.com>. 2001-06-17 02:05:20 +00:00
Tom Lane 01a819abe3 Make planner compute the number of hash buckets the same way that
nodeHash.c will compute it (by sharing code).
2001-06-11 00:17:08 +00:00
Tom Lane a8fe109ac1 Fix thinko in hash cost estimation: average frequency
should be computed from total number of distinct values in whole
relation, not # distinct values we expect to have after restriction
clauses are applied.
2001-06-10 02:59:35 +00:00
Tom Lane cdd230d628 Improve planning of OR indexscan plans: for quals like
WHERE (a = 1 or a = 2) and b = 42
and an index on (a,b), include the clause b = 42 in the indexquals
generated for each arm of the OR clause.  Essentially this is an index-
driven conversion from CNF to DNF.  Implementation is a bit klugy, but
better than not exploiting the extra quals at all ...
2001-06-05 17:13:52 +00:00
Tom Lane 7c579fa12d Further work on making use of new statistics in planner. Adjust APIs
of costsize.c routines to pass Query root, so that costsize can figure
more things out by itself and not be so dependent on its callers to tell
it everything it needs to know.  Use selectivity of hash or merge clause
to estimate number of tuples processed internally in these joins
(this is more useful than it would've been before, since eqjoinsel is
somewhat more accurate than before).
2001-06-05 05:26:05 +00:00
Peter Eisentraut 12c1552066 Mark many strings in backend not covered by elog for translation. Also,
make strings in xlog.c look more like English and less like binary noise.
2001-06-03 14:53:56 +00:00
Tom Lane be03eb25f3 Modify optimizer data structures so that IndexOptInfo lists built for
create_index_paths are not immediately discarded, but are available for
subsequent planner work.  This allows avoiding redundant syscache lookups
in several places.  Change interface to operator selectivity estimation
procedures to allow faster and more flexible estimation.
Initdb forced due to change of pg_proc entries for selectivity functions!
2001-05-20 20:28:20 +00:00
Tom Lane 248182560c Current implementation of FOR UPDATE has no hope of working correctly
for relations on the nullable side of an OUTER JOIN.  For now I think
we'd better refuse such queries.
2001-05-14 20:25:00 +00:00
Tom Lane c23bc6fbb0 First cut at making indexscan cost estimates depend on correlation
between index order and table order.
2001-05-09 23:13:37 +00:00
Tom Lane 6cda3ad8fe Cause planner to make use of average-column-width statistic that is now
collected by ANALYZE.  Also, add some modest amount of intelligence to
guesses that are used for varlena columns in the absence of any ANALYZE
statistics.  The 'width' reported by EXPLAIN is finally something less
than totally bogus for varlena columns ... and, in consequence, hashjoin
estimating should be a little better ...
2001-05-09 00:35:09 +00:00
Bruce Momjian 857abb0e57 Add newlines around debug output in optimizer showing total costs. 2001-05-08 17:25:28 +00:00
Tom Lane f905d65ee3 Rewrite of planner statistics-gathering code. ANALYZE is now available as
a separate statement (though it can still be invoked as part of VACUUM, too).
pg_statistic redesigned to be more flexible about what statistics are
stored.  ANALYZE now collects a list of several of the most common values,
not just one, plus a histogram (not just the min and max values).  Random
sampling is used to make the process reasonably fast even on very large
tables.  The number of values and histogram bins collected is now
user-settable via an ALTER TABLE command.

There is more still to do; the new stats are not being used everywhere
they could be in the planner.  But the remaining changes for this project
should be localized, and the behavior is already better than before.

A not-very-related change is that sorting now makes use of btree comparison
routines if it can find one, rather than invoking '<' twice.
2001-05-07 00:43:27 +00:00
Tom Lane e2004dfc69 Suppress pull-up of subqueries that are in the nullable side of an outer
join.  This is needed to avoid improper evaluation of expressions that
should be nulled out, as in Victor Wagner's bug report of 4/27/01.
Pretty ugly solution, but no time to do anything better for 7.1.1.
2001-04-30 19:24:47 +00:00
Tom Lane a43f20cb0a Tweak nestloop costing to weight restart cost of inner path more heavily.
Without this, it was making some pretty silly decisions about whether an
expensive sub-SELECT should be the inner or outer side of a join...
2001-04-25 22:04:37 +00:00
Tom Lane d5096af2c4 Make the world safe for passing whole rows of views to functions. This
already worked fine for whole rows of tables, but not so well for views...
2001-04-18 20:42:56 +00:00
Tom Lane cdcaec5c53 Avoid reversing user-given order of WHERE clauses while attaching clauses
to specific base or join RelOptInfo nodes during planning.  This preserves
the more-intuitive behavior of 7.0.* --- if you write an expensive clause
(such as a sub-select) last, it should get evaluated last.  Someday we
ought to try to have some intelligence about the order of evaluation of
WHERE clauses, but for now we should not override what the user wrote.
2001-04-16 19:44:10 +00:00
Tom Lane f9094c44c0 Prevent generation of invalid plans for RIGHT or FULL joins with multiple
join clauses.  The mergejoin executor wants all the join clauses to appear
as merge quals, not as extra joinquals, for these kinds of joins.  But the
planner would consider plans in which partially-sorted input paths were
used, leading to only some of the join clauses becoming merge quals.
This is fine for inner/left joins, not fine for right/full joins.
2001-04-15 00:48:17 +00:00
Tom Lane 2ef99ee708 Planner wasn't correctly handling adjustment of tuple_fraction for the
case of LIMIT in a sub-select.
2001-04-01 22:37:19 +00:00
Tom Lane f155cc82ec Quick hack to fix Oliver Elphick's problem with subselects in an
inheritance query: make duplicate copies of subplans in adjust_inherited_attrs.
When we redesign querytrees we really gotta do something about this
issue of whether querytrees are read-only and can share substructure
or not.
2001-03-27 18:02:19 +00:00
Tom Lane fa0f2c6577 Repair pgindent damage to comments. 2001-03-27 17:12:34 +00:00
Bruce Momjian 7cf952e7b4 Fix comments that were mis-wrapped, for Tom Lane. 2001-03-23 04:49:58 +00:00
Bruce Momjian 0686d49da0 Remove dashes in comments that don't need them, rewrap with pgindent. 2001-03-22 06:16:21 +00:00
Bruce Momjian 9e1552607a pgindent run. Make it all clean. 2001-03-22 04:01:46 +00:00
Tom Lane d73e9df087 A subplan invoked within an aggregate function's argument should
be allowed to receive ungrouped variables of the current query level.
Curious that no one reported this bug before...
2001-03-08 01:49:01 +00:00