summaryrefslogtreecommitdiff
path: root/src/backend/parser/analyze.c
Commit message (Collapse)AuthorAgeFilesLines
* Implement subselects in target lists. Also, relax requirement thatTom Lane1999-11-151-2/+5
| | | | | | | | | | | | | subselects can only appear on the righthand side of a binary operator. That's still true for quantified predicates like x = ANY (SELECT ...), but a subselect that delivers a single result can now appear anywhere in an expression. This is implemented by changing EXPR_SUBLINK sublinks to represent just the (SELECT ...) expression, without any 'left hand side' or combining operator --- so they're now more like EXISTS_SUBLINK. To handle the case of '(x, y, z) = (SELECT ...)', I added a new sublink type MULTIEXPR_SUBLINK, which acts just like EXPR_SUBLINK used to. But the grammar will only generate one for a multiple-left-hand-side row expression.
* New NameStr macro to convert Name to Str. No need for var.data anymore.Bruce Momjian1999-11-071-2/+2
| | | | | | Fewer calls to nameout. Better use of RelationGetRelationName.
* Eliminate local inefficiencies in updateTargetListEntry, make_var, andTom Lane1999-11-011-23/+36
| | | | make_const --- don't repeat cache searches that aren't needed.
* Fix planner and rewriter to follow SQL semantics for tables that areTom Lane1999-10-071-25/+7
| | | | | | | | | | | mentioned in FROM but not elsewhere in the query: such tables should be joined over anyway. Aside from being more standards-compliant, this allows removal of some very ugly hacks for COUNT(*) processing. Also, allow HAVING clause without aggregate functions, since SQL does. Clean up CREATE RULE statement-list syntax the same way Bruce just fixed the main stmtmulti production. CAUTION: addition of a field to RangeTblEntry nodes breaks stored rules; you will have to initdb if you have any rules.
* Reimplement parsing and storage of default expressions and constraintTom Lane1999-10-031-76/+81
| | | | | | | | | | | | | | | expressions in CREATE TABLE. There is no longer an emasculated expression syntax for these things; it's full a_expr for constraints, and b_expr for defaults (unfortunately the fact that NOT NULL is a part of the column constraint syntax causes a shift/reduce conflict if you try a_expr. Oh well --- at least parenthesized boolean expressions work now). Also, stored expression for a column default is not pre-coerced to the column type; we rely on transformInsertStatement to do that when the default is actually used. This means "f1 datetime default 'now'" behaves the way people usually expect it to. BTW, all the support code is now there to implement ALTER TABLE ADD CONSTRAINT and ALTER TABLE ADD COLUMN with a default value. I didn't actually teach ALTER TABLE to call it, but it wouldn't be much work.
* Mega-commit to make heap_open/heap_openr/heap_close take anTom Lane1999-09-181-4/+4
| | | | | | | | | | | | | | | | | additional argument specifying the kind of lock to acquire/release (or 'NoLock' to do no lock processing). Ensure that all relations are locked with some appropriate lock level before being examined --- this ensures that relevant shared-inval messages have been processed and should prevent problems caused by concurrent VACUUM. Fix several bugs having to do with mismatched increment/decrement of relation ref count and mismatched heap_open/close (which amounts to the same thing). A bogus ref count on a relation doesn't matter much *unless* a SI Inval message happens to arrive at the wrong time, which is probably why we got away with this sloppiness for so long. Repair missing grab of AccessExclusiveLock in DROP TABLE, ALTER/RENAME TABLE, etc, as noted by Hiroshi. Recommend 'make clean all' after pulling this update; I modified the Relation struct layout slightly. Will post further discussion to pghackers list shortly.
* Major revision of sort-node handling: push knowledge of queryTom Lane1999-08-211-3/+1
| | | | | | | | | | | | | sort order down into planner, instead of handling it only at the very top level of the planner. This fixes many things. An explicit sort is now avoided if there is a cheaper alternative (typically an indexscan) not only for ORDER BY, but also for the internal sort of GROUP BY. It works even when there is no other reason (such as a WHERE condition) to consider the indexscan. It works for indexes on functions. It works for indexes on functions, backwards. It's just so cool... CAUTION: I have changed the representation of SortClause nodes, therefore THIS UPDATE BREAKS STORED RULES. You will need to initdb.
* Repair the check for redundant UNIQUE and PRIMARY KEY indices.Thomas G. Lockhart1999-08-151-13/+33
| | | | | Also, improve it so that it checks for multi-column constraints. Thanks to Mark Dalphin <mdalphin@amgen.com> for reporting the problem.
* Rewrite parser's handling of INSERT ... SELECT so that processingTom Lane1999-07-191-141/+204
| | | | | | | | | of the SELECT part of the statement is just like a plain SELECT. All INSERT-specific processing happens after the SELECT parsing is done. This eliminates many problems, e.g. INSERT ... SELECT ... GROUP BY using the wrong column labels. Ensure that DEFAULT clauses are coerced to the target column type, whether or not stored clause produces the right type. Substantial cleanup of parser's array support.
* Move some system includes into c.h, and remove duplicates.Bruce Momjian1999-07-171-5/+1
|
* Final cleanup.Bruce Momjian1999-07-161-4/+4
|
* Remove unused #includes in *.c files.Bruce Momjian1999-07-151-5/+1
|
* Clean up #include in /include directory. Add scripts for checking includes.Bruce Momjian1999-07-151-2/+1
|
* Remove S*I comments from Stephan.Bruce Momjian1999-07-131-7/+1
|
* Instead of failing when the constructed name for a sequence,Tom Lane1999-06-051-85/+92
| | | | index, etc is too long, truncate until it fits.
* Make 0x007f -> (unsigned)0x7f to make pgindent happy.Bruce Momjian1999-05-251-2/+2
|
* pgindent run over code.Bruce Momjian1999-05-251-140/+153
|
* Detect case of invalid use of GROUP BY when there are noTom Lane1999-05-231-3/+3
| | | | | | | aggregate functions, as in select a, b from foo group by a; The ungrouped reference to b is not kosher, but formerly we neglected to check this unless there was an aggregate function somewhere in the query.
* Change resjunk to a boolean.Bruce Momjian1999-05-171-2/+2
|
* Prior patch added 2 more characters to string allocatedTom Lane1999-05-171-2/+2
| | | | for SERIAL column's constraint, but forgot to increase space palloc'd...
* Add double quotes around the sequence name generated to support theThomas G. Lockhart1999-05-131-45/+18
| | | | | | SERIAL data type DEFAULT clause. This fixes a problem finding the sequence name when mixed case table names are involved.
* Rip out QueryTreeList structure, root and branch. QuerytreeTom Lane1999-05-131-31/+16
| | | | | | | | | | lists are now plain old garden-variety Lists, allocated with palloc, rather than specialized expansible-array data allocated with malloc. This substantially simplifies their handling and eliminates several sources of memory leakage. Several basic types of erroneous queries (syntax error, attempt to insert a duplicate key into a unique index) now demonstrably leak zero bytes per query.
* Fix problem with multiple indices defined if using column- and table-Thomas G. Lockhart1999-05-121-24/+68
| | | | | | | constraints. Reported by Tom Lane. Now, check for duplicate indices and retain the one which is a primary-key. Adjust elog NOTICE messages to surround table and column names with single quotes.
* Put in explicit checks for implicit index name lengths.Thomas G. Lockhart1999-02-231-15/+54
| | | | | Put in hooks for outer joins by passing a few parameters back and forth in function calls. May not be close to working yet.
* From: Tatsuo Ishii <t-ishii@sra.co.jp>Marc G. Fournier1999-02-211-2/+2
| | | | | | Ok. I made patches replacing all of "#if FALSE" or "#if 0" to "#ifdef NOT_USED" for current. I have tested these patches in that the postgres binaries are identical.
* Change my-function-name-- to my_function_name, and optimizer renames.Bruce Momjian1999-02-131-2/+2
|
* Added LIMIT/OFFSET functionality including new regression test for it.Jan Wieck1999-02-081-1/+5
| | | | | | | Removed CURRENT keyword for rule queries and changed rules regression accordingly. CURRENT has beed announced to disappear in v6.5. Jan
* Add TEMP tables/indexes. Add COPY pfree(). Other cleanups.Bruce Momjian1999-02-021-2/+4
|
* From: Tatsuo Ishii <t-ishii@sra.co.jp>Marc G. Fournier1999-01-271-5/+2
| | | | | | Included patches fix a portability problem of unsetenv() used in 6.4.2 multi-byte support. unsetenv() is only avaliable on FreeBSD and Linux so I decided to replace with putenv().
* SELECT FOR UPDATE is implemented...Vadim B. Mikheev1999-01-251-2/+18
|
* The following patch finishes primary key support. Previously, whenBruce Momjian1999-01-211-1/+5
| | | | | | | | | | | | | | | | | | | | a field was labelled as a primary key, the system automatically created a unique index on the field. This patch extends it so that the index has the indisprimary field set. You can pull a list of primary keys with the followiing select. SELECT pg_class.relname, pg_attribute.attname FROM pg_class, pg_attribute, pg_index WHERE pg_class.oid = pg_attribute.attrelid AND pg_class.oid = pg_index.indrelid AND pg_index.indkey[0] = pg_attribute.attnum AND pg_index.indisunique = 't'; There is nothing in this patch that modifies the template database to set the indisprimary attribute for system tables. Should they be changed or should we only be concerned with user tables? D'Arcy
* FOR UPDATE is in parser & rules.Vadim B. Mikheev1999-01-211-2/+66
|
* Hi!Bruce Momjian1999-01-181-4/+113
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | INTERSECT and EXCEPT is available for postgresql-v6.4! The patch against v6.4 is included at the end of the current text (in uuencoded form!) I also included the text of my Master's Thesis. (a postscript version). I hope that you find something of it useful and would be happy if parts of it find their way into the PostgreSQL documentation project (If so, tell me, then I send the sources of the document!) The contents of the document are: -) The first chapter might be of less interest as it gives only an overview on SQL. -) The second chapter gives a description on much of PostgreSQL's features (like user defined types etc. and how to use these features) -) The third chapter starts with an overview of PostgreSQL's internal structure with focus on the stages a query has to pass (i.e. parser, planner/optimizer, executor). Then a detailed description of the implementation of the Having clause and the Intersect/Except logic is given. Originally I worked on v6.3.2 but never found time enough to prepare and post a patch. Now I applied the changes to v6.4 to get Intersect and Except working with the new version. Chapter 3 of my documentation deals with the changes against v6.3.2, so keep that in mind when comparing the parts of the code printed there with the patched sources of v6.4. Here are some remarks on the patch. There are some things that have still to be done but at the moment I don't have time to do them myself. (I'm doing my military service at the moment) Sorry for that :-( -) I used a rewrite technique for the implementation of the Except/Intersect logic which rewrites the query to a semantically equivalent query before it is handed to the rewrite system (for views, rules etc.), planner, executor etc. -) In v6.3.2 the types of the attributes of two select statements connected by the UNION keyword had to match 100%. In v6.4 the types only need to be familiar (i.e. int and float can be mixed). Since this feature did not exist when I worked on Intersect/Except it does not work correctly for Except/Intersect queries WHEN USED IN COMBINATION WITH UNIONS! (i.e. sometimes the wrong type is used for the resulting table. This is because until now the types of the attributes of the first select statement have been used for the resulting table. When Intersects and/or Excepts are used in combination with Unions it might happen, that the first select statement of the original query appears at another position in the query which will be executed. The reason for this is the technique used for the implementation of Except/Intersect which does a query rewrite!) NOTE: It is NOT broken for pure UNION queries and pure INTERSECT/EXCEPT queries!!! -) I had to add the field intersect_clause to some data structures but did not find time to implement printfuncs for the new field. This does NOT break the debug modes but when an Except/Intersect is used the query debug output will be the already rewritten query. -) Massive changes to the grammar rules for SELECT and INSERT statements have been necessary (see comments in gram.y and documentation for deatails) in order to be able to use mixed queries like (SELECT ... UNION (SELECT ... EXCEPT SELECT)) INTERSECT SELECT...; -) When using UNION/EXCEPT/INTERSECT you will get: NOTICE: equal: "Don't know if nodes of type xxx are equal". I did not have time to add comparsion support for all the needed nodes, but the default behaviour of the function equal met my requirements. I did not dare to supress this message! That's the reason why the regression test for union will fail: These messages are also included in the union.out file! -) Somebody of you changed the union_planner() function for v6.4 (I copied the targetlist to new_tlist and that was removed and replaced by a cleanup of the original targetlist). These chnages violated some having queries executed against views so I changed it back again. I did not have time to examine the differences between the two versions but now it works :-) If you want to find out, try the file queries/view_having.sql on both versions and compare the results . Two queries won't produce a correct result with your version. regards Stefan
* Many more cleanups...Marc G. Fournier1998-12-141-3/+1
|
* Implement CASE expression.Thomas G. Lockhart1998-12-041-13/+12
|
* Fix for serial creation.Bruce Momjian1998-10-281-11/+32
|
* Clean up code in analyze.c for SERIAL data type.Thomas G. Lockhart1998-09-251-11/+7
| | | | Remove _all_ PARSEDEBUG print statements.
* Support specifying PRIMARY KEY for the SERIAL type.Thomas G. Lockhart1998-09-161-7/+16
| | | | | Check for a constraint if is_sequence is set and omit making a UNIQUE index if so, since the primary key will cover that for us.
* Allow insert statements to have every columnThomas G. Lockhart1998-09-031-6/+21
| | | | supplied by a DEFAULT clause. Enables INSERT INTO TABLE DEFAULT VALUES...
* OK, folks, here is the pgindent output.Bruce Momjian1998-09-011-48/+60
|
* Renaming cleanup, no pgindent yet.Bruce Momjian1998-09-011-5/+5
|
* Make attalign match type alignment.Bruce Momjian1998-08-261-6/+6
|
* Fix up crashing symptoms for new serial type by making sure constraintThomas G. Lockhart1998-08-261-2/+3
| | | | and index name fields are pstrdup'd (copied) rather than reused.
* Support SERIAL column type. Expand column marked is_sequence into threeThomas G. Lockhart1998-08-251-3/+42
| | | | | | | | | | statements: - the table definition with a default clause referencing the sequence; - a CREATE SEQUENCE statement; - a UNIQUE constraint, which expands into a CREATE INDEX statement. This is not a perfect solution, since the sequence will remain even if the table is dropped. Also, there is no absolute protection on updating the sequence column.
* From: Jan Wieck <jwieck@debis.com>Marc G. Fournier1998-08-181-2/+26
| | | | | | | | | Hi, as proposed here comes the first patch for the query rewrite system. <for details, see archive dated Mon, 17 Aug 1998>
* makeTargetEntry cleanup.Bruce Momjian1998-07-201-2/+2
|
* Cleanup makeTargetEntry and remove internal.c.Bruce Momjian1998-07-201-6/+4
|
* 1) Queries using the having clause on base tables should work wellBruce Momjian1998-07-191-1/+25
| | | | | | | | | | | | | | | | | | | | | | | | | now. Here some tested features, (examples included in the patch): 1.1) Subselects in the having clause 1.2) Double nested subselects 1.3) Subselects used in the where clause and in the having clause simultaneously 1.4) Union Selects using having 1.5) Indexes on the base relations are used correctly 1.6) Unallowed Queries are prevented (e.g. qualifications in the having clause that belong to the where clause) 1.7) Insert into as select 2) Queries using the having clause on view relations also work but there are some restrictions: 2.1) Create View as Select ... Having ...; using base tables in the select 2.1.1) The Query rewrite system: 2.1.2) Why are only simple queries allowed against a view from 2.1) ? 2.2) Select ... from testview1, testview2, ... having...; 3) Bug in ExecMergeJoin ?? Regards Stefan
* Fix up a couple of comments broken by the automatic indenting process.Thomas G. Lockhart1998-05-291-8/+11
|
* Add capabilities for automatic type conversion.Thomas G. Lockhart1998-05-091-1/+8
|