Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit449020f

Browse files
author
Thomas G. Lockhart
committed
Put in explicit checks for implicit index name lengths.
Put in hooks for outer joins by passing a few parameters back and forth in function calls. May not be close to working yet.
1 parent03d5c07 commit449020f

File tree

1 file changed

+54
-15
lines changed

1 file changed

+54
-15
lines changed

‎src/backend/parser/analyze.c

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Id: analyze.c,v 1.100 1999/02/21 03:48:59 scrappy Exp $
8+
* $Id: analyze.c,v 1.101 1999/02/23 07:44:44 thomas Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -240,12 +240,12 @@ transformDeleteStmt(ParseState *pstate, DeleteStmt *stmt)
240240
qry->commandType=CMD_DELETE;
241241

242242
/* set up a range table */
243-
makeRangeTable(pstate,stmt->relname,NULL);
243+
makeRangeTable(pstate,stmt->relname,NULL,NULL);
244244

245245
qry->uniqueFlag=NULL;
246246

247247
/* fix where clause */
248-
qry->qual=transformWhereClause(pstate,stmt->whereClause);
248+
qry->qual=transformWhereClause(pstate,stmt->whereClause,NULL);
249249
qry->hasSubLinks=pstate->p_hasSubLinks;
250250

251251
qry->rtable=pstate->p_rtable;
@@ -272,7 +272,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
272272
pstate->p_is_insert= true;
273273

274274
/* set up a range table */
275-
makeRangeTable(pstate,stmt->relname,stmt->fromClause);
275+
makeRangeTable(pstate,stmt->relname,stmt->fromClause,NULL);
276276

277277
qry->uniqueFlag=stmt->unique;
278278

@@ -360,15 +360,15 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
360360
}
361361

362362
/* fix where clause */
363-
qry->qual=transformWhereClause(pstate,stmt->whereClause);
363+
qry->qual=transformWhereClause(pstate,stmt->whereClause,NULL);
364364

365365
/*
366366
* The havingQual has a similar meaning as "qual" in the where
367367
* statement. So we can easily use the code from the "where clause"
368368
* with some additional traversals done in
369369
* .../optimizer/plan/planner.c
370370
*/
371-
qry->havingQual=transformWhereClause(pstate,stmt->havingClause);
371+
qry->havingQual=transformWhereClause(pstate,stmt->havingClause,NULL);
372372

373373
qry->hasSubLinks=pstate->p_hasSubLinks;
374374

@@ -553,6 +553,10 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
553553
CreateSeqStmt*sequence;
554554

555555
sname=makeTableName(stmt->relname,column->colname,"seq",NULL);
556+
if (sname==NULL)
557+
elog(ERROR,"CREATE TABLE/SERIAL implicit sequence name must be less than %d characters"
558+
"\n\tSum of lengths of '%s' and '%s' must be less than %d",
559+
NAMEDATALEN,stmt->relname,column->colname, (NAMEDATALEN-5));
556560

557561
constraint=makeNode(Constraint);
558562
constraint->contype=CONSTR_DEFAULT;
@@ -581,6 +585,10 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
581585
constraint=makeNode(Constraint);
582586
constraint->contype=CONSTR_UNIQUE;
583587
constraint->name=makeTableName(stmt->relname,column->colname,"key",NULL);
588+
if (constraint->name==NULL)
589+
elog(ERROR,"CREATE TABLE/SERIAL implicit index name must be less than %d characters"
590+
"\n\tSum of lengths of '%s' and '%s' must be less than %d",
591+
NAMEDATALEN,stmt->relname,column->colname, (NAMEDATALEN-5));
584592
column->constraints=lappend(column->constraints,constraint);
585593
}
586594

@@ -602,6 +610,16 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
602610
constraint=lfirst(clist);
603611
switch (constraint->contype)
604612
{
613+
caseCONSTR_NULL:
614+
/* We should mark this explicitly,
615+
* so we can tell if NULL and NOT NULL are both specified
616+
*/
617+
if (column->is_not_null)
618+
elog(ERROR,"CREATE TABLE/(NOT) NULL conflicting declaration"
619+
" for %s.%s",stmt->relname,column->colname);
620+
column->is_not_null= FALSE;
621+
break;
622+
605623
caseCONSTR_NOTNULL:
606624
if (column->is_not_null)
607625
elog(ERROR,"CREATE TABLE/NOT NULL already specified"
@@ -619,6 +637,10 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
619637
caseCONSTR_PRIMARY:
620638
if (constraint->name==NULL)
621639
constraint->name=makeTableName(stmt->relname,"pkey",NULL);
640+
if (constraint->name==NULL)
641+
elog(ERROR,"CREATE TABLE/PRIMARY KEY implicit index name must be less than %d characters"
642+
"\n\tLength of '%s' must be less than %d",
643+
NAMEDATALEN,stmt->relname, (NAMEDATALEN-6));
622644
if (constraint->keys==NIL)
623645
constraint->keys=lappend(constraint->keys,column);
624646
dlist=lappend(dlist,constraint);
@@ -627,6 +649,10 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
627649
caseCONSTR_UNIQUE:
628650
if (constraint->name==NULL)
629651
constraint->name=makeTableName(stmt->relname,column->colname,"key",NULL);
652+
if (constraint->name==NULL)
653+
elog(ERROR,"CREATE TABLE/UNIQUE implicit index name must be less than %d characters"
654+
"\n\tLength of '%s' must be less than %d",
655+
NAMEDATALEN,stmt->relname, (NAMEDATALEN-5));
630656
if (constraint->keys==NIL)
631657
constraint->keys=lappend(constraint->keys,column);
632658
dlist=lappend(dlist,constraint);
@@ -636,6 +662,10 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
636662
constraints=lappend(constraints,constraint);
637663
if (constraint->name==NULL)
638664
constraint->name=makeTableName(stmt->relname,column->colname,NULL);
665+
if (constraint->name==NULL)
666+
elog(ERROR,"CREATE TABLE/CHECK implicit constraint name must be less than %d characters"
667+
"\n\tSum of lengths of '%s' and '%s' must be less than %d",
668+
NAMEDATALEN,stmt->relname,column->colname, (NAMEDATALEN-1));
639669
break;
640670

641671
default:
@@ -654,6 +684,10 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
654684
caseCONSTR_PRIMARY:
655685
if (constraint->name==NULL)
656686
constraint->name=makeTableName(stmt->relname,"pkey",NULL);
687+
if (constraint->name==NULL)
688+
elog(ERROR,"CREATE TABLE/PRIMARY KEY implicit index name must be less than %d characters"
689+
"\n\tLength of '%s' must be less than %d",
690+
NAMEDATALEN,stmt->relname, (NAMEDATALEN-5));
657691
dlist=lappend(dlist,constraint);
658692
break;
659693

@@ -695,7 +729,7 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
695729
*
696730
* Note that this code does not currently look for all possible redundant cases
697731
*and either ignore or stop with warning. The create might fail later when
698-
*names for indices turn out to beredundant, or a user might have specified
732+
*names for indices turn out to beduplicated, or a user might have specified
699733
*extra useless indices which might hurt performance. - thomas 1997-12-08
700734
*/
701735
while (dlist!=NIL)
@@ -728,6 +762,10 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
728762

729763
have_pkey= TRUE;
730764
index->idxname=makeTableName(stmt->relname,"pkey",NULL);
765+
if (index->idxname==NULL)
766+
elog(ERROR,"CREATE TABLE/PRIMARY KEY implicit index name must be less than %d characters"
767+
"\n\tLength of '%s' must be less than %d",
768+
NAMEDATALEN,stmt->relname, (NAMEDATALEN-5));
731769
}
732770
else
733771
index->idxname=NULL;
@@ -803,7 +841,7 @@ transformIndexStmt(ParseState *pstate, IndexStmt *stmt)
803841
qry->commandType=CMD_UTILITY;
804842

805843
/* take care of the where clause */
806-
stmt->whereClause=transformWhereClause(pstate,stmt->whereClause);
844+
stmt->whereClause=transformWhereClause(pstate,stmt->whereClause,NULL);
807845
qry->hasSubLinks=pstate->p_hasSubLinks;
808846

809847
stmt->rangetable=pstate->p_rtable;
@@ -827,7 +865,7 @@ transformExtendStmt(ParseState *pstate, ExtendStmt *stmt)
827865
qry->commandType=CMD_UTILITY;
828866

829867
/* take care of the where clause */
830-
stmt->whereClause=transformWhereClause(pstate,stmt->whereClause);
868+
stmt->whereClause=transformWhereClause(pstate,stmt->whereClause,NULL);
831869
qry->hasSubLinks=pstate->p_hasSubLinks;
832870

833871
stmt->rangetable=pstate->p_rtable;
@@ -902,7 +940,7 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt)
902940
}
903941

904942
/* take care of the where clause */
905-
stmt->whereClause=transformWhereClause(pstate,stmt->whereClause);
943+
stmt->whereClause=transformWhereClause(pstate,stmt->whereClause,NULL);
906944
qry->hasSubLinks=pstate->p_hasSubLinks;
907945

908946
qry->utilityStmt= (Node*)stmt;
@@ -919,11 +957,12 @@ static Query *
919957
transformSelectStmt(ParseState*pstate,SelectStmt*stmt)
920958
{
921959
Query*qry=makeNode(Query);
960+
Node*qual;
922961

923962
qry->commandType=CMD_SELECT;
924963

925964
/* set up a range table */
926-
makeRangeTable(pstate,NULL,stmt->fromClause);
965+
makeRangeTable(pstate,NULL,stmt->fromClause,&qual);
927966

928967
qry->uniqueFlag=stmt->unique;
929968

@@ -933,14 +972,14 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt)
933972

934973
qry->targetList=transformTargetList(pstate,stmt->targetList);
935974

936-
qry->qual=transformWhereClause(pstate,stmt->whereClause);
975+
qry->qual=transformWhereClause(pstate,stmt->whereClause,qual);
937976

938977
/*
939978
* The havingQual has a similar meaning as "qual" in the where
940979
* statement. So we can easily use the code from the "where clause"
941980
* with some additional traversals done in optimizer/plan/planner.c
942981
*/
943-
qry->havingQual=transformWhereClause(pstate,stmt->havingClause);
982+
qry->havingQual=transformWhereClause(pstate,stmt->havingClause,NULL);
944983

945984
qry->hasSubLinks=pstate->p_hasSubLinks;
946985

@@ -1006,11 +1045,11 @@ transformUpdateStmt(ParseState *pstate, UpdateStmt *stmt)
10061045
* the FROM clause is non-standard SQL syntax. We used to be able to
10071046
* do this with REPLACE in POSTQUEL so we keep the feature.
10081047
*/
1009-
makeRangeTable(pstate,stmt->relname,stmt->fromClause);
1048+
makeRangeTable(pstate,stmt->relname,stmt->fromClause,NULL);
10101049

10111050
qry->targetList=transformTargetList(pstate,stmt->targetList);
10121051

1013-
qry->qual=transformWhereClause(pstate,stmt->whereClause);
1052+
qry->qual=transformWhereClause(pstate,stmt->whereClause,NULL);
10141053
qry->hasSubLinks=pstate->p_hasSubLinks;
10151054

10161055
qry->rtable=pstate->p_rtable;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp