Merge rename name page into alter table. Fix UNION with DISTINCT
or ORDER BY bug.
This commit is contained in:
parent
62943bb76f
commit
d7050cb68c
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.21 1998/03/30 19:04:41 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.22 1998/03/31 04:43:49 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -64,12 +64,13 @@ plan_union_queries(Query *parse)
|
||||
{
|
||||
List *union_plans = NIL,
|
||||
*ulist,
|
||||
*unionall_queries,
|
||||
*union_all_queries,
|
||||
*union_rts,
|
||||
*last_union = NIL;
|
||||
*last_union = NIL,
|
||||
*hold_sortClause = parse->sortClause;
|
||||
bool union_all_found = false,
|
||||
union_found = false,
|
||||
last_unionall_flag = false;
|
||||
last_union_all_flag = false;
|
||||
|
||||
/*------------------------------------------------------------------
|
||||
*
|
||||
@ -120,17 +121,25 @@ plan_union_queries(Query *parse)
|
||||
union_found = true;
|
||||
last_union = ulist;
|
||||
}
|
||||
last_unionall_flag = union_query->unionall;
|
||||
last_union_all_flag = union_query->unionall;
|
||||
}
|
||||
|
||||
/* Is this a simple one */
|
||||
if (!union_all_found ||
|
||||
!union_found ||
|
||||
/* A trailing UNION negates the affect of earlier UNION ALLs */
|
||||
!last_unionall_flag)
|
||||
!last_union_all_flag)
|
||||
{
|
||||
List *hold_unionClause = parse->unionClause;
|
||||
|
||||
/* we will do this later, so don't do it now */
|
||||
if (!union_all_found ||
|
||||
!last_union_all_flag)
|
||||
{
|
||||
parse->sortClause = NIL;
|
||||
parse->uniqueFlag = NULL;
|
||||
}
|
||||
|
||||
parse->unionClause = NIL; /* prevent recursion */
|
||||
union_plans = lcons(union_planner(parse), NIL);
|
||||
union_rts = lcons(parse->rtable, NIL);
|
||||
@ -154,7 +163,7 @@ plan_union_queries(Query *parse)
|
||||
*/
|
||||
|
||||
/* save off everthing past the last UNION */
|
||||
unionall_queries = lnext(last_union);
|
||||
union_all_queries = lnext(last_union);
|
||||
|
||||
/* clip off the list to remove the trailing UNION ALLs */
|
||||
lnext(last_union) = NIL;
|
||||
@ -167,21 +176,21 @@ plan_union_queries(Query *parse)
|
||||
union_rts = lcons(parse->rtable, NIL);
|
||||
|
||||
/* Append the remainging UNION ALLs */
|
||||
foreach(ulist, unionall_queries)
|
||||
foreach(ulist, union_all_queries)
|
||||
{
|
||||
Query *unionall_query = lfirst(ulist);
|
||||
Query *union_all_query = lfirst(ulist);
|
||||
|
||||
union_plans = lappend(union_plans, union_planner(unionall_query));
|
||||
union_rts = lappend(union_rts, unionall_query->rtable);
|
||||
union_plans = lappend(union_plans, union_planner(union_all_query));
|
||||
union_rts = lappend(union_rts, union_all_query->rtable);
|
||||
}
|
||||
}
|
||||
|
||||
/* We have already split UNION and UNION ALL and we made it consistent */
|
||||
if (!last_unionall_flag)
|
||||
if (!last_union_all_flag)
|
||||
{
|
||||
parse->uniqueFlag = "*";
|
||||
parse->sortClause = transformSortClause(NULL, NIL,
|
||||
parse->sortClause,
|
||||
hold_sortClause,
|
||||
parse->targetList, "*");
|
||||
}
|
||||
else
|
||||
@ -195,7 +204,7 @@ plan_union_queries(Query *parse)
|
||||
union_rts,
|
||||
0,
|
||||
NULL,
|
||||
((Plan *) lfirst(union_plans))->targetlist));
|
||||
parse->targetList));
|
||||
}
|
||||
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.14 1998/03/18 15:47:51 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.15 1998/03/31 04:43:53 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -313,7 +313,13 @@ transformSortClause(ParseState *pstate,
|
||||
{
|
||||
SortClause *sortcl = lfirst(s);
|
||||
|
||||
if (sortcl->resdom == tlelt->resdom)
|
||||
/*
|
||||
* We use equal() here because we are called for UNION
|
||||
* from the optimizer, and at that point, the sort clause
|
||||
* resdom pointers don't match the target list resdom
|
||||
* pointers
|
||||
*/
|
||||
if (equal(sortcl->resdom, tlelt->resdom))
|
||||
break;
|
||||
s = lnext(s);
|
||||
}
|
||||
|
@ -1,25 +1,33 @@
|
||||
.\" This is -*-nroff-*-
|
||||
.\" XXX standard disclaimer belongs here....
|
||||
.\" $Header: /cvsroot/pgsql/src/man/Attic/alter_table.l,v 1.4 1998/01/11 22:17:04 momjian Exp $
|
||||
.\" $Header: /cvsroot/pgsql/src/man/Attic/alter_table.l,v 1.5 1998/03/31 04:44:19 momjian Exp $
|
||||
.TH "ALTER TABLE" SQL 09/25/97 PostgreSQL
|
||||
.SH NAME
|
||||
alter table - add attributes to a class
|
||||
alter table - add attributes to a class, or rename an attribute or class
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
\fBalter table\fR classname [ * ]
|
||||
\fBadd\fR [ \fBcolumn\fR ] attname type
|
||||
.fi
|
||||
.nf
|
||||
\fBalter table\fR classname [ * ]
|
||||
\fBadd\fR \fB(\fR attname type \fB)\fR
|
||||
|
||||
\fBalter table\fR classname1
|
||||
\fBrename to\fR classname2
|
||||
|
||||
\fBalter table\fR classname1 [\fB*\fR]
|
||||
\fBrename [column]\fR attname1 \fBto\fR attname2
|
||||
.fi
|
||||
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.BR "alter table"
|
||||
command
|
||||
causes a new attribute to be added to an existing class,
|
||||
.IR classname .
|
||||
command causes a new attribute to be added to an existing class,
|
||||
.IR classname ,
|
||||
or the name of a class or attribute to change
|
||||
without changing any of the data contained in the affected class.
|
||||
Thus, the class or attribute will remain of the same type and size
|
||||
after this command is executed.
|
||||
.PP
|
||||
The new attributes and their types are specified
|
||||
in the same style and with the the same restrictions as in
|
||||
.IR "create table" (l).
|
||||
@ -33,7 +41,9 @@ attribute will not be added to any of the subclasses.) This should
|
||||
be done when adding an attribute to a superclass. If it is not,
|
||||
queries on the inheritance hierarchy such as
|
||||
.nf
|
||||
select * from super* s
|
||||
|
||||
select * from super* s
|
||||
|
||||
.fi
|
||||
will not work because the subclasses will be missing an attribute
|
||||
found in the superclass.
|
||||
@ -45,6 +55,24 @@ desired, a subsequent
|
||||
.IR update (l)
|
||||
query should be run.
|
||||
.PP
|
||||
In order to rename an attribute in each class in an entire inheritance
|
||||
hierarchy, use the
|
||||
.IR classname
|
||||
of the superclass and append a \*(lq*\*(rq. (By default, the attribute
|
||||
will not be renamed in any of the subclasses.) This should
|
||||
.BR always
|
||||
be done when changing an attribute name in a superclass. If it is
|
||||
not, queries on the inheritance hierarchy such as
|
||||
.nf
|
||||
select * from super* s
|
||||
.fi
|
||||
will not work because the subclasses will be (in effect) missing an
|
||||
attribute found in the superclass.
|
||||
.PP
|
||||
You must own the class being modified in order to rename it or part of
|
||||
its schema. Renaming any part of the schema of a system catalog is
|
||||
not permitted.
|
||||
.PP
|
||||
You must own the class in order to change its schema.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
@ -52,14 +80,25 @@ You must own the class in order to change its schema.
|
||||
-- add the date of hire to the emp class
|
||||
--
|
||||
alter table emp add column hiredate abstime
|
||||
.fi
|
||||
.nf
|
||||
--
|
||||
-- add a health-care number to all persons
|
||||
-- (including employees, students, ...)
|
||||
--
|
||||
alter table person * add column health_care_id int4
|
||||
--
|
||||
-- change the emp class to personnel
|
||||
--
|
||||
alter table emp rename to personnel
|
||||
--
|
||||
-- change the sports attribute to hobbies
|
||||
--
|
||||
alter table emp rename column sports to hobbies
|
||||
--
|
||||
-- make a change to an inherited attribute
|
||||
--
|
||||
alter table person * rename column last_name to family_name
|
||||
.fi
|
||||
.SH "SEE ALSO"
|
||||
create table (l),
|
||||
update (l).
|
||||
|
||||
|
@ -1,63 +0,0 @@
|
||||
.\" This is -*-nroff-*-
|
||||
.\" XXX standard disclaimer belongs here....
|
||||
.\" $Header: /cvsroot/pgsql/src/man/Attic/rename.l,v 1.3 1998/01/11 22:17:55 momjian Exp $
|
||||
.TH RENAME SQL 02/08/94 PostgreSQL PostgreSQL
|
||||
.SH NAME
|
||||
rename - rename a class or an attribute in a class
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
\fBalter table\fR classname1
|
||||
\fBrename to\fR classname2
|
||||
\fBalter table\fR classname1 [\fB*\fR]
|
||||
\fBrename [column]\fR attname1 \fBto\fR attname2
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.BR rename
|
||||
command
|
||||
causes the name of a class or attribute to change without changing any
|
||||
of the data contained in the affected class. Thus, the class or
|
||||
attribute will remain of the same type and size after this command is
|
||||
executed.
|
||||
.PP
|
||||
In order to rename an attribute in each class in an entire inheritance
|
||||
hierarchy, use the
|
||||
.IR classname
|
||||
of the superclass and append a \*(lq*\*(rq. (By default, the attribute
|
||||
will not be renamed in any of the subclasses.) This should
|
||||
.BR always
|
||||
be done when changing an attribute name in a superclass. If it is
|
||||
not, queries on the inheritance hierarchy such as
|
||||
.nf
|
||||
select * from super* s
|
||||
.fi
|
||||
will not work because the subclasses will be (in effect) missing an
|
||||
attribute found in the superclass.
|
||||
.PP
|
||||
You must own the class being modified in order to rename it or part of
|
||||
its schema. Renaming any part of the schema of a system catalog is
|
||||
not permitted.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
--
|
||||
-- change the emp class to personnel
|
||||
--
|
||||
alter table emp rename to personnel
|
||||
.fi
|
||||
.nf
|
||||
--
|
||||
-- change the sports attribute to hobbies
|
||||
--
|
||||
alter table emp rename column sports to hobbies
|
||||
.fi
|
||||
.nf
|
||||
--
|
||||
-- make a change to an inherited attribute
|
||||
--
|
||||
alter table person * rename column last_name to family_name
|
||||
.fi
|
||||
.SH BUGS
|
||||
Execution of historical queries using classes and attributes whose
|
||||
names have changed will produce incorrect results in many situations.
|
||||
.PP
|
||||
Renaming of types, operators, rules, etc., should also be supported.
|
54
src/test/regress/sql/name.sql
Normal file
54
src/test/regress/sql/name.sql
Normal file
@ -0,0 +1,54 @@
|
||||
--**************** testing built-in type name **************
|
||||
--
|
||||
-- all inputs are silently truncated at NAMEDATALEN (32) characters
|
||||
--
|
||||
|
||||
-- fixed-length by reference
|
||||
SELECT 'name string'::name = 'name string'::name AS "True";
|
||||
|
||||
SELECT 'name string'::name = 'name string '::name AS "False";
|
||||
|
||||
--
|
||||
--
|
||||
--
|
||||
|
||||
CREATE TABLE NAME_TBL(f1 name);
|
||||
|
||||
INSERT INTO NAME_TBL(f1) VALUES ('ABCDEFGHIJKLMNOP');
|
||||
|
||||
INSERT INTO NAME_TBL(f1) VALUES ('abcdefghijklmnop');
|
||||
|
||||
INSERT INTO NAME_TBL(f1) VALUES ('asdfghjkl;');
|
||||
|
||||
INSERT INTO NAME_TBL(f1) VALUES ('343f%2a');
|
||||
|
||||
INSERT INTO NAME_TBL(f1) VALUES ('d34aaasdf');
|
||||
|
||||
INSERT INTO NAME_TBL(f1) VALUES ('');
|
||||
|
||||
INSERT INTO NAME_TBL(f1) VALUES ('1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ');
|
||||
|
||||
|
||||
SELECT '' AS seven, NAME_TBL.*;
|
||||
|
||||
SELECT '' AS six, c.f1 FROM NAME_TBL c WHERE c.f1 <> 'ABCDEFGHIJKLMNOP';
|
||||
|
||||
SELECT '' AS one, c.f1 FROM NAME_TBL c WHERE c.f1 = 'ABCDEFGHIJKLMNOP';
|
||||
|
||||
SELECT '' AS three, c.f1 FROM NAME_TBL c WHERE c.f1 < 'ABCDEFGHIJKLMNOP';
|
||||
|
||||
SELECT '' AS four, c.f1 FROM NAME_TBL c WHERE c.f1 <= 'ABCDEFGHIJKLMNOP';
|
||||
|
||||
SELECT '' AS three, c.f1 FROM NAME_TBL c WHERE c.f1 > 'ABCDEFGHIJKLMNOP';
|
||||
|
||||
SELECT '' AS four, c.f1 FROM NAME_TBL c WHERE c.f1 >= 'ABCDEFGHIJKLMNOP';
|
||||
|
||||
SELECT '' AS seven, c.f1 FROM NAME_TBL c WHERE c.f1 ~ '.*';
|
||||
|
||||
SELECT '' AS zero, c.f1 FROM NAME_TBL c WHERE c.f1 !~ '.*';
|
||||
|
||||
SELECT '' AS three, c.f1 FROM NAME_TBL c WHERE c.f1 ~ '[0-9]';
|
||||
|
||||
SELECT '' AS two, c.f1 FROM NAME_TBL c WHERE c.f1 ~ '.*asdf.*';
|
||||
|
||||
DROP TABLE NAME_TBL;
|
Loading…
x
Reference in New Issue
Block a user