Commit Graph

709 Commits

Author SHA1 Message Date
Tom Lane b89140a7ec Do honest transformation and preprocessing of LIMIT/OFFSET clauses,
instead of the former kluge whereby gram.y emitted already-transformed
expressions.  This is needed so that Params appearing in these clauses
actually work correctly.  I suppose some might claim that the side effect
of 'SELECT ... LIMIT 2+2' working is a new feature, but I say this is
a bug fix.
2003-07-03 19:07:54 +00:00
Tom Lane 455891bf96 Code review for UPDATE tab SET col = DEFAULT patch ... whack it around
so it has some chance of working in rules ...
2003-07-03 16:34:26 +00:00
Tom Lane 02b5d8e371 Dept. of second thoughts: supporting inlining of polymorphic SQL functions
takes only a few more lines of code than preventing it, so might as well
support it.
2003-07-01 19:07:02 +00:00
Tom Lane d6d07a0eea SQL functions can have arguments and results declared ANYARRAY or
ANYELEMENT.  The effect is to postpone typechecking of the function
body until runtime.  Documentation is still lacking.

Original patch by Joe Conway, modified to postpone type checking
by Tom Lane.
2003-07-01 00:04:39 +00:00
Tom Lane 835bb975d8 Restructure building of join relation targetlists so that a join plan
node emits only those vars that are actually needed above it in the
plan tree.  (There were comments in the code suggesting that this was
done at some point in the dim past, but for a long time we have just
made join nodes emit everything that either input emitted.)  Aside from
being marginally more efficient, this fixes the problem noted by Peter
Eisentraut where a join above an IN-implemented-as-join might fail,
because the subplan targetlist constructed in the latter case didn't
meet the expectation of including everything.
Along the way, fix some places that were O(N^2) in the targetlist
length.  This is not all the trouble spots for wide queries by any
means, but it's a step forward.
2003-06-29 23:05:05 +00:00
Tom Lane bee217924d Support expressions of the form 'scalar op ANY (array)' and
'scalar op ALL (array)', where the operator is applied between the
lefthand scalar and each element of the array.  The operator must
yield boolean; the result of the construct is the OR or AND of the
per-element results, respectively.

Original coding by Joe Conway, after an idea of Peter's.  Rewritten
by Tom to keep the implementation strictly separate from subqueries.
2003-06-29 00:33:44 +00:00
Bruce Momjian 111d8e522b Back out array mega-patch.
Joe Conway
2003-06-25 21:30:34 +00:00
Bruce Momjian 46bf651480 Array mega-patch.
Joe Conway
2003-06-24 23:14:49 +00:00
Tom Lane a499725469 Allow GROUP BY, ORDER BY, DISTINCT targets to be unknown literals,
silently resolving them to type TEXT.  This is comparable to what we
do when faced with UNKNOWN in CASE, UNION, and other contexts.  It gets
rid of this and related annoyances:
	select distinct f1, '' from int4_tbl;
	ERROR:  Unable to identify an ordering operator '<' for type unknown
This was discussed many moons ago, but no one got round to fixing it.
2003-06-16 02:03:38 +00:00
Tom Lane cb02610e50 Adjust nestloop-with-inner-indexscan plan generation so that we catch
some cases of redundant clauses that were formerly not caught.  We have
to special-case this because the clauses involved never get attached to
the same join restrictlist and so the existing logic does not notice
that they are redundant.
2003-06-15 22:51:45 +00:00
Tom Lane e649796f12 Implement outer-level aggregates to conform to the SQL spec, with
extensions to support our historical behavior.  An aggregate belongs
to the closest query level of any of the variables in its argument,
or the current query level if there are no variables (e.g., COUNT(*)).
The implementation involves adding an agglevelsup field to Aggref,
and treating outer aggregates like outer variables at planning time.
2003-06-06 15:04:03 +00:00
Tom Lane 7c7139cf29 Knock down a couple more lappend() hotspots for large WHERE clauses. 2003-05-28 23:06:16 +00:00
Tom Lane 8a6ac83dab Fix some planner performance problems with large WHERE clauses, by
introducing new 'FastList' list-construction subroutines to use in
hot spots.  This avoids the O(N^2) behavior of repeated lappend's
by keeping a tail pointer, while not changing behavior by reversing
list order as the lcons() method would do.
2003-05-28 22:32:50 +00:00
Tom Lane fc8d970cbc Replace functional-index facility with expressional indexes. Any column
of an index can now be a computed expression instead of a simple variable.
Restrictions on expressions are the same as for predicates (only immutable
functions, no sub-selects).  This fixes problems recently introduced with
inlining SQL functions, because the inlining transformation is applied to
both expression trees so the planner can still match them up.  Along the
way, improve efficiency of handling index predicates (both predicates and
index expressions are now cached by the relcache) and fix 7.3 oversight
that didn't record dependencies of predicate expressions.
2003-05-28 16:04:02 +00:00
Bruce Momjian 98b6f37e47 Make debug_ GUC varables output DEBUG1 rather than LOG, and mention in
docs that CLIENT/LOG_MIN_MESSAGES now controls debug_* output location.
Doc changes included.
2003-05-27 17:49:47 +00:00
Tom Lane f45df8c014 Cause CHAR(n) to TEXT or VARCHAR conversion to automatically strip trailing
blanks, in hopes of reducing the surprise factor for newbies.  Remove
redundant operators for VARCHAR (it depends wholly on TEXT operations now).
Clean up resolution of ambiguous operators/functions to avoid surprising
choices for domains: domains are treated as equivalent to their base types
and binary-coercibility is no longer considered a preference item when
choosing among multiple operators/functions.  IsBinaryCoercible now correctly
reflects the notion that you need *only* relabel the type to get from type
A to type B: that is, a domain is binary-coercible to its base type, but
not vice versa.  Various marginal cleanup, including merging the essentially
duplicate resolution code in parse_func.c and parse_oper.c.  Improve opr_sanity
regression test to understand about binary compatibility (using pg_cast),
and fix a couple of small errors in the catalogs revealed thereby.
Restructure "special operator" handling to fetch operators via index opclasses
rather than hardwiring assumptions about names (cleans up the pattern_ops
stuff a little).
2003-05-26 00:11:29 +00:00
Tom Lane 9e43184b9d Add missing #include. 2003-05-15 19:34:46 +00:00
Peter Eisentraut 2c0556068f Indexing support for pattern matching operations via separate operator
class when lc_collate is not C.
2003-05-15 15:50:21 +00:00
Tom Lane 1c9ac7dfd0 Change pg_amop's index on (amopclaid,amopopr) to index (amopopr,amopclaid).
This makes no difference for existing uses, but allows SelectSortFunction()
and pred_test_simple_clause() to use indexscans instead of seqscans to
locate entries for a particular operator in pg_amop.  Better yet, they can
use the SearchSysCacheList() API to cache the search results.
2003-05-13 04:38:58 +00:00
Tom Lane d97c9b3662 Apply fixes for problems with dropped columns whose types have also been
dropped.  The simplest fix for INSERT/UPDATE cases turns out to be for
preptlist.c to insert NULLs of a known-good type (I used INT4) rather
than making them match the deleted column's type.  Since the representation
of NULL is actually datatype-independent, this should work fine.
I also re-reverted the patch to disable the use_physical_tlist optimization
in the presence of dropped columns.  It still doesn't look worth the
trouble to be smarter, if there are no other bugs to fix.
Added a regression test to catch future problems in this area.
2003-05-12 00:17:03 +00:00
Tom Lane 6f261461c1 Revert previous change --- turns out the underlying problem affects
more cases than I thought, so ExecTypeFromTL() will have to be fixed
anyway.
2003-05-11 20:25:50 +00:00
Tom Lane 8f2e53bc10 Disable the recently-added use_physical_tlist optimization in cases
where the table contains dropped columns.  If the columns are dropped,
then their types may be gone as well, which causes ExecTypeFromTL() to
fail if the dropped columns appear in a plan node's tlist.  This could
be worked around but I don't think the optimization is valuable enough
to be worth the trouble.
2003-05-11 15:03:52 +00:00
Tom Lane 2cf57c8f8d Implement feature of new FE/BE protocol whereby RowDescription identifies
the column by table OID and column number, if it's a simple column
reference.  Along the way, get rid of reskey/reskeyop fields in Resdoms.
Turns out that representation was not convenient for either the planner
or the executor; we can make the planner deliver exactly what the
executor wants with no more effort.
initdb forced due to change in stored rule representation.
2003-05-06 00:20:33 +00:00
Tom Lane de28dc9a04 Portal and memory management infrastructure for extended query protocol.
Both plannable queries and utility commands are now always executed
within Portals, which have been revamped so that they can handle the
load (they used to be good only for single SELECT queries).  Restructure
code to push command-completion-tag selection logic out of postgres.c,
so that it won't have to be duplicated between simple and extended queries.
initdb forced due to addition of a field to Query nodes.
2003-05-02 20:54:36 +00:00
Tom Lane 1940434f1e Repair sloppiness about where cached mergeclause pathkeys are allocated.
Without this fix, CVS tip dumps core when running the regression tests
with geqo_threshold = 2.  I would think that a similar patch might be
needed in 7.3, but cannot duplicate the failure in that branch --- so
for now, leave well enough alone.
2003-05-02 19:48:53 +00:00
Tom Lane aa282d4446 Infrastructure for deducing Param types from context, in the same way
that the types of untyped string-literal constants are deduced (ie,
when coerce_type is applied to 'em, that's what the type must be).
Remove the ancient hack of storing the input Param-types array as a
global variable, and put the info into ParseState instead.  This touches
a lot of files because of adjustment of routine parameter lists, but
it's really not a large patch.  Note: PREPARE statement still insists on
exact specification of parameter types, but that could easily be relaxed
now, if we wanted to do so.
2003-04-29 22:13:11 +00:00
Tom Lane 982430f846 Put back encoding-conversion step in processing of incoming queries;
I had inadvertently omitted it while rearranging things to support
length-counted incoming messages.  Also, change the parser's API back
to accepting a 'char *' query string instead of 'StringInfo', as the
latter wasn't buying us anything except overhead.  (I think when I put
it in I had some notion of making the parser API 8-bit-clean, but
seeing that flex depends on null-terminated input, that's not really
ever gonna happen.)
2003-04-27 20:09:44 +00:00
Tom Lane 5f677af2da Adjust subquery qual pushdown rules so that we can push down a qual
into a UNION that has some type coercions applied to the component
queries, so long as the qual itself does not reference any columns that
have such coercions.  Per example from Jonathan Bartlett 24-Apr-03.
2003-04-24 23:43:09 +00:00
Tom Lane 730840c9b6 First phase of work on array improvements. ARRAY[x,y,z] constructor
expressions, ARRAY(sub-SELECT) expressions, some array functions.
Polymorphic functions using ANYARRAY/ANYELEMENT argument and return
types.  Some regression tests in place, documentation is lacking.
Joe Conway, with some kibitzing from Tom Lane.
2003-04-08 23:20:04 +00:00
Tom Lane efeffae245 Tweak selectivity and related routines to cope with domains. Per report
from Andreas Pflug.
2003-03-23 01:49:02 +00:00
Tom Lane 9323cb0aab Department of second thoughts: probably shouldn't use nth() to get the
appropriate targetlist entry out of the subquery.  Use an explicit search
like we do everywhere else.
2003-03-22 17:11:25 +00:00
Tom Lane 05f916e6ad Adjust subquery qual pushdown rules to be more forgiving: if a qual
refers to a non-DISTINCT output column of a DISTINCT ON subquery, or
if it refers to a function-returning-set, we cannot push it down.
But the old implementation refused to push down *any* quals if the
subquery had any such 'dangerous' outputs.  Now we just look at the
output columns actually referenced by each qual expression.  More code
than before, but probably no slower since we don't make unnecessary checks.
2003-03-22 01:49:38 +00:00
Tom Lane 7931bfa764 Make eval_const_expressions simplify FieldSelect from a whole-row Var
into an ordinary one-field Var.  Per example from Chris Mungall.
2003-03-14 00:55:17 +00:00
Tom Lane 6c4996fa6b GROUP BY got confused if there were multiple equal() GROUP BY items.
This bug has been latent since 7.0 or maybe even further back, but it
was only exposed when parse_clause.c stopped suppressing duplicate
items (see its rev 1.96 of 18-Aug-02).
2003-03-13 16:58:35 +00:00
Tom Lane aa83bc04e0 Restructure parsetree representation of DECLARE CURSOR: now it's a
utility statement (DeclareCursorStmt) with a SELECT query dangling from
it, rather than a SELECT query with a few unusual fields in it.  Add
code to determine whether a planned query can safely be run backwards.
If DECLARE CURSOR specifies SCROLL, ensure that the plan can be run
backwards by adding a Materialize plan node if it can't.  Without SCROLL,
you get an error if you try to fetch backwards from a cursor that can't
handle it.  (There is still some discussion about what the exact
behavior should be, but this is necessary infrastructure in any case.)
Along the way, make EXPLAIN DECLARE CURSOR work.
2003-03-10 03:53:52 +00:00
Tom Lane 21591967bc Turns out new IN implementation has got some problems in an UPDATE or
DELETE with inherited target table.  Fix it; add a regression test.
Also, correct ancient misspelling of 'inherited'.
2003-03-05 20:01:04 +00:00
Tom Lane 147fbf9c6e Repair bug reported by Laurent Perez: bad plan generated when UPDATE or
DELETE of an inheritance tree references another inherited relation.
This bug has been latent since 7.1; I'm still not quite sure why 7.1 and
7.2 don't manifest it (at least, they don't crash on a simple test case).
2003-03-05 18:38:14 +00:00
Tom Lane 30a695d356 Be smart about outer-join qualifications that mention only one side of
the join, per recent discussion on pgsql-sql.  Not clear that this will
come up often in real queries, but it's not any more expensive to do it
right, so we may as well do it right.
2003-03-02 23:46:34 +00:00
Tom Lane 72933a92c7 Back off previous patch to skip projection step in scan plan nodes,
in the case where the node immediately above the scan is a Hash, Sort,
or Material node.  In these cases it's better to do the projection
so that we don't store unneeded columns in the hash/sort/materialize
table.  Per discussion a few days ago with Anagh Lal.
2003-02-16 06:06:32 +00:00
Tom Lane 51972a9d5d COALESCE() and NULLIF() are now first-class expressions, not macros
that turn into CASE expressions.  They evaluate their arguments at most
once.  Patch by Kris Jurka, review and (very light) editorializing by me.
2003-02-16 02:30:39 +00:00
Tom Lane 0d7abfe7cf Marginal tweaks to make sure that roundoff error won't cause us to make
a bad choice between sorted and hashed aggregation.
2003-02-15 21:39:58 +00:00
Tom Lane 056467ec6b Teach planner how to propagate pathkeys from sub-SELECTs in FROM up to
the outer query.  (The implementation is a bit klugy, but it would take
nontrivial restructuring to make it nicer, which this is probably not
worth.)  This avoids unnecessary sort steps in examples like
SELECT foo,count(*) FROM (SELECT ... ORDER BY foo,bar) sub GROUP BY foo
which means there is now a reasonable technique for controlling the
order of inputs to custom aggregates, even in the grouping case.
2003-02-15 20:12:41 +00:00
Tom Lane 8a4fdce9f2 Fix thinko in new logic about pushing down non-nullability constraints:
constraints appearing in outer-join qualification clauses are restricted
as to when and where they can be pushed down.  Add regression test
to catch future errors in this area.
2003-02-10 17:08:50 +00:00
Tom Lane b5956a2f22 Detect case where an outer join can be reduced to a plain inner join
because there are WHERE clauses that will reject the null-extended rows.
Per suggestion from Brandon Craig Rhodes, 19-Nov-02.
2003-02-09 23:57:19 +00:00
Tom Lane 39b7ec3309 Create a distinction between Lists of integers and Lists of OIDs, to get
rid of the assumption that sizeof(Oid)==sizeof(int).  This is one small
step towards someday supporting 8-byte OIDs.  For the moment, it doesn't
do much except get rid of a lot of unsightly casts.
2003-02-09 06:56:28 +00:00
Tom Lane 3646ab58b4 Remove bogus comment (too freely copied & pasted). 2003-02-09 00:35:55 +00:00
Tom Lane 145014f811 Make further use of new bitmapset code: executor's chgParam, extParam,
locParam lists can be converted to bitmapsets to speed updating.  Also,
replace 'locParam' with 'allParam', which contains all the paramIDs
relevant to the node (i.e., the union of extParam and locParam); this
saves a step during SetChangedParamList() without costing anything
elsewhere.
2003-02-09 00:30:41 +00:00
Tom Lane c15a4c2aef Replace planner's representation of relation sets, per pghackers discussion.
Instead of Lists of integers, we now store variable-length bitmap sets.
This should be faster as well as less error-prone.
2003-02-08 20:20:55 +00:00
Tom Lane 00f1a41ab2 Make flatten_join_alias_vars() do the right thing when expanding an alias
referenced from a subquery.  Per example from Stefanos Harhalakis.
2003-02-06 22:21:11 +00:00
Tom Lane 2d1f940542 Minor code cleanup: remove no-longer-useful pull_subplans() function,
and convert pull_agg_clause() into count_agg_clause(), which is a more
efficient way of doing what it's really being used for.
2003-02-04 00:50:01 +00:00