aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2016-02-29 13:44:38 +0000
committerdrh <drh@noemail.net>2016-02-29 13:44:38 +0000
commit743606c3d3843dcc25be65bcb3cce2e10f8d752c (patch)
treea196492c127ed36d09fc8cce9ed4e2b030f356ca /src
parent94fa9c414a4998f60d99d6a65e1d104fe62d2436 (diff)
parent986dde705234f9a9e9e60f4d75eb60dd0c94ccf3 (diff)
downloadsqlite-743606c3d3843dcc25be65bcb3cce2e10f8d752c.tar.gz
sqlite-743606c3d3843dcc25be65bcb3cce2e10f8d752c.zip
Very minor improvement to the performance and reduction in size to the
parser by capturing the name and datatype of table columns in a single grammar rule reduction. FossilOrigin-Name: 4b55c520f554163edc174e5995e66242f169cb04
Diffstat (limited to 'src')
-rw-r--r--src/build.c40
-rw-r--r--src/parse.y30
-rw-r--r--src/sqliteInt.h3
3 files changed, 21 insertions, 52 deletions
diff --git a/src/build.c b/src/build.c
index bcf71442d..ec8770a45 100644
--- a/src/build.c
+++ b/src/build.c
@@ -1038,7 +1038,7 @@ void sqlite3ColumnPropertiesFromName(Table *pTab, Column *pCol){
** first to get things going. Then this routine is called for each
** column.
*/
-void sqlite3AddColumn(Parse *pParse, Token *pName){
+void sqlite3AddColumn(Parse *pParse, Token *pName, Token *pType){
Table *p;
int i;
char *z;
@@ -1074,13 +1074,17 @@ void sqlite3AddColumn(Parse *pParse, Token *pName){
pCol->zName = z;
sqlite3ColumnPropertiesFromName(p, pCol);
- /* If there is no type specified, columns have the default affinity
- ** 'BLOB'. If there is a type specified, then sqlite3AddColumnType() will
- ** be called next to set pCol->affinity correctly.
- */
- pCol->affinity = SQLITE_AFF_BLOB;
- pCol->szEst = 1;
+ if( pType->n==0 ){
+ /* If there is no type specified, columns have the default affinity
+ ** 'BLOB'. */
+ pCol->affinity = SQLITE_AFF_BLOB;
+ pCol->szEst = 1;
+ }else{
+ pCol->zType = sqlite3NameFromToken(pParse->db, pType);
+ pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst);
+ }
p->nCol++;
+ pParse->constraintName.n = 0;
}
/*
@@ -1184,28 +1188,6 @@ char sqlite3AffinityType(const char *zIn, u8 *pszEst){
}
/*
-** This routine is called by the parser while in the middle of
-** parsing a CREATE TABLE statement. The pFirst token is the first
-** token in the sequence of tokens that describe the type of the
-** column currently under construction. pLast is the last token
-** in the sequence. Use this information to construct a string
-** that contains the typename of the column and store that string
-** in zType.
-*/
-void sqlite3AddColumnType(Parse *pParse, Token *pType){
- Table *p;
- Column *pCol;
-
- p = pParse->pNewTable;
- if( p==0 || NEVER(p->nCol<1) ) return;
- pCol = &p->aCol[p->nCol-1];
- assert( pCol->zType==0 || CORRUPT_DB );
- sqlite3DbFree(pParse->db, pCol->zType);
- pCol->zType = sqlite3NameFromToken(pParse->db, pType);
- pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst);
-}
-
-/*
** The expression is the default value for the most recently added column
** of the table currently under construction.
**
diff --git a/src/parse.y b/src/parse.y
index e7e0d1d95..20492edb8 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -190,22 +190,9 @@ table_options(A) ::= WITHOUT nm(X). {
sqlite3ErrorMsg(pParse, "unknown table option: %.*s", X.n, X.z);
}
}
-columnlist ::= columnlist COMMA column.
-columnlist ::= column.
-
-// A "column" is a complete description of a single column in a
-// CREATE TABLE statement. This includes the column name, its
-// datatype, and other keywords such as PRIMARY KEY, UNIQUE, REFERENCES,
-// NOT NULL and so forth.
-//
-column(A) ::= columnid(A) type carglist. {
- A.n = (int)(pParse->sLastToken.z-A.z) + pParse->sLastToken.n;
-}
-columnid(A) ::= nm(A). {
- sqlite3AddColumn(pParse,&A);
- pParse->constraintName.n = 0;
-}
-
+columnlist ::= columnlist COMMA columnname carglist.
+columnlist ::= columnname carglist.
+columnname(A) ::= nm(A) typetoken(Y). {sqlite3AddColumn(pParse,&A,&Y);}
// An IDENTIFIER can be a generic identifier, or one of several
// keywords. Any non-standard keyword can also be an identifier.
@@ -264,13 +251,12 @@ nm(A) ::= id(A).
nm(A) ::= STRING(A).
nm(A) ::= JOIN_KW(A).
-// A typetoken is really one or more tokens that form a type name such
+// A typetoken is really zero or more tokens that form a type name such
// as can be found after the column name in a CREATE TABLE statement.
// Multiple tokens are concatenated to form the value of the typetoken.
//
%type typetoken {Token}
-type ::= .
-type ::= typetoken(X). {sqlite3AddColumnType(pParse,&X);}
+typetoken(A) ::= . {A.n = 0; A.z = 0;}
typetoken(A) ::= typename(A).
typetoken(A) ::= typename(A) LP signed RP(Y). {
A.n = (int)(&Y.z[Y.n] - A.z);
@@ -580,7 +566,7 @@ selcollist(A) ::= sclp(A) nm(X) DOT STAR(Y). {
%type as {Token}
as(X) ::= AS nm(Y). {X = Y;}
as(X) ::= ids(X).
-as(X) ::= . {X.n = 0;}
+as(X) ::= . {X.n = 0; X.z = 0;}
%type seltablist {SrcList*}
@@ -1499,7 +1485,9 @@ cmd ::= ANALYZE nm(X) dbnm(Y). {sqlite3Analyze(pParse, &X, &Y);}
cmd ::= ALTER TABLE fullname(X) RENAME TO nm(Z). {
sqlite3AlterRenameTable(pParse,X,&Z);
}
-cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column(Y). {
+cmd ::= ALTER TABLE add_column_fullname
+ ADD kwcolumn_opt columnname(Y) carglist. {
+ Y.n = (int)(pParse->sLastToken.z-Y.z) + pParse->sLastToken.n;
sqlite3AlterFinishAddColumn(pParse, &Y);
}
add_column_fullname ::= fullname(X). {
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 7d1757e4d..d6acc3227 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -3413,11 +3413,10 @@ void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
#else
# define sqlite3ColumnPropertiesFromName(T,C) /* no-op */
#endif
-void sqlite3AddColumn(Parse*,Token*);
+void sqlite3AddColumn(Parse*,Token*,Token*);
void sqlite3AddNotNull(Parse*, int);
void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
void sqlite3AddCheckConstraint(Parse*, Expr*);
-void sqlite3AddColumnType(Parse*,Token*);
void sqlite3AddDefaultValue(Parse*,ExprSpan*);
void sqlite3AddCollateType(Parse*, Token*);
void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);