[patches] [PATCH 1/3] sql: remove hidden column attribute

Alex Khatskevich avkhatskevich at tarantool.org
Thu Feb 22 15:44:03 MSK 2018


Ack


On 14.02.2018 15:38, Nikita Pettik wrote:
> As part of Tarantool data dictionary integration into SQL, all usages of
> colflag (i.e. field in struct Column) after space creation should be
> removed. Currently, colflag indicates one of three statuses:
> primary key column, hidden column and column with specified type.
> Since there is no more any hidden columns, this patch removes all
> code connected with them.
with -> to?
>
> Part of #3118
>
> Signed-off-by: Nikita Pettik <korablev at tarantool.org>
> ---
>   src/box/sql/build.c     | 17 -----------------
>   src/box/sql/delete.c    |  2 +-
>   src/box/sql/insert.c    | 35 +++++++----------------------------
>   src/box/sql/pragma.c    |  8 +-------
>   src/box/sql/select.c    | 14 --------------
>   src/box/sql/sqliteInt.h | 26 --------------------------
>   src/box/sql/whereexpr.c |  6 +-----
>   7 files changed, 10 insertions(+), 98 deletions(-)
>
> diff --git a/src/box/sql/build.c b/src/box/sql/build.c
> index 2777e8073..ae140ee3c 100644
> --- a/src/box/sql/build.c
> +++ b/src/box/sql/build.c
> @@ -760,22 +760,6 @@ sqlite3StartTable(Parse *pParse, Token *pName, int noErr)
>   	return;
>   }
>   
> -/* Set properties of a table column based on the (magical)
> - * name of the column.
> - */
> -#if SQLITE_ENABLE_HIDDEN_COLUMNS
> -void
> -sqlite3ColumnPropertiesFromName(Table * pTab, Column * pCol)
> -{
> -	if (sqlite3_strnicmp(pCol->zName, "__hidden__", 10) == 0) {
> -		pCol->colFlags |= COLFLAG_HIDDEN;
> -	} else if (pTab && pCol != pTab->aCol
> -		   && (pCol[-1].colFlags & COLFLAG_HIDDEN)) {
> -		pTab->tabFlags |= TF_OOOHidden;
> -	}
> -}
> -#endif
> -
>   /*
>    * Add a new column to the table currently being constructed.
>    *
> @@ -828,7 +812,6 @@ sqlite3AddColumn(Parse * pParse, Token * pName, Token * pType)
>   	pCol = &p->aCol[p->nCol];
>   	memset(pCol, 0, sizeof(p->aCol[0]));
>   	pCol->zName = z;
> -	sqlite3ColumnPropertiesFromName(p, pCol);
>   
>   	if (pType->n == 0) {
>   		/* If there is no type specified, columns have the default affinity
> diff --git a/src/box/sql/delete.c b/src/box/sql/delete.c
> index b15f43844..9320625e0 100644
> --- a/src/box/sql/delete.c
> +++ b/src/box/sql/delete.c
> @@ -123,7 +123,7 @@ sqlite3MaterializeView(Parse * pParse,	/* Parsing context */
>   		assert(pFrom->a[0].pUsing == 0);
>   	}
>   	pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0,
> -				SF_IncludeHidden, 0, 0);
> +				0, 0, 0);
>   	sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur);
>   	sqlite3Select(pParse, pSel, &dest);
>   	sqlite3SelectDelete(db, pSel);
> diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c
> index bc1906fb6..82a8c2c31 100644
> --- a/src/box/sql/insert.c
> +++ b/src/box/sql/insert.c
> @@ -216,7 +216,7 @@ xferOptimization(Parse * pParse,	/* Parser context */
>    *    insert into TABLE (IDLIST) default values
>    *
>    * The IDLIST following the table name is always optional.  If omitted,
> - * then a list of all (non-hidden) columns for the table is substituted.
> + * then a list of all columns for the table is substituted.
>    * The IDLIST appears in the pColumn parameter.  pColumn is NULL if IDLIST
>    * is omitted.
>    *
> @@ -319,7 +319,6 @@ sqlite3Insert(Parse * pParse,	/* Parser context */
>   	Vdbe *v;		/* Generate code into this virtual machine */
>   	Index *pIdx;		/* For looping over indices of the table */
>   	int nColumn;		/* Number of columns in the data */
> -	int nHidden = 0;	/* Number of hidden columns. */
>   	int iDataCur = 0;	/* VDBE cursor that is the main data repository */
>   	int iIdxCur = 0;	/* First index cursor */
>   	int ipkColumn = -1;	/* Column that is the INTEGER PRIMARY KEY */
> @@ -453,7 +452,7 @@ sqlite3Insert(Parse * pParse,	/* Parser context */
>   	 * is appears in the original table.  (The index of the INTEGER
>   	 * PRIMARY KEY in the original table is pTab->iPKey.)
>   	 */
> -	bIdListInOrder = (pTab->tabFlags & TF_OOOHidden) == 0;
> +	bIdListInOrder = 1;
>   	if (pColumn) {
>   		for (i = 0; i < pColumn->nId; i++) {
>   			pColumn->a[i].idx = -1;
> @@ -588,16 +587,10 @@ sqlite3Insert(Parse * pParse,	/* Parser context */
>   		ipkColumn = pTab->iPKey;
>   	}
>   
> -	/* Make sure the number of columns in the source data matches the number
> -	 * of columns to be inserted into the table.
> -	 */
> -	for (i = 0; i < pTab->nCol; i++) {
> -		nHidden += (IsHiddenColumn(&pTab->aCol[i]) ? 1 : 0);
> -	}
> -	if (pColumn == 0 && nColumn && nColumn != (pTab->nCol - nHidden)) {
> +	if (pColumn == 0 && nColumn && nColumn != (pTab->nCol)) {
>   		sqlite3ErrorMsg(pParse,
>   				"table %S has %d columns but %d values were supplied",
> -				pTabList, 0, pTab->nCol - nHidden, nColumn);
> +				pTabList, 0, pTab->nCol, nColumn);
>   		goto insert_cleanup;
>   	}
>   	if (pColumn != 0 && nColumn != pColumn->nId) {
> @@ -677,9 +670,7 @@ sqlite3Insert(Parse * pParse,	/* Parser context */
>   				}
>   			}
>   			if ((!useTempTable && !pList)
> -			    || (pColumn && j >= pColumn->nId)
> -			    || (pColumn == 0
> -				&& IsOrdinaryHiddenColumn(&pTab->aCol[i]))) {
> +			    || (pColumn && j >= pColumn->nId)) {
>   				if (i == pTab->iAutoIncPKey)
>   					sqlite3VdbeAddOp2(v, OP_Integer, -1,
>   							  regCols + i + 1);
> @@ -696,8 +687,7 @@ sqlite3Insert(Parse * pParse,	/* Parser context */
>   							pList->a[j].pExpr,
>   							regCols + i + 1);
>   			}
> -			if (pColumn == 0
> -			    && !IsOrdinaryHiddenColumn(&pTab->aCol[i]))
> +			if (pColumn == 0)
>   				j++;
>   		}
>   
> @@ -739,16 +729,10 @@ sqlite3Insert(Parse * pParse,	/* Parser context */
>   		/* Compute data for all columns of the new entry, beginning
>   		 * with the first column.
>   		 */
> -		nHidden = 0;
>   		for (i = 0; i < pTab->nCol; i++) {
>   			int iRegStore = regTupleid + 1 + i;
>   			if (pColumn == 0) {
> -				if (IsHiddenColumn(&pTab->aCol[i])) {
> -					j = -1;
> -					nHidden++;
> -				} else {
> -					j = i - nHidden;
> -				}
> +				j = i;
>   			} else {
>   				for (j = 0; j < pColumn->nId; j++) {
>   					if (pColumn->a[j].idx == i)
> @@ -1807,11 +1791,6 @@ xferOptimization(Parse * pParse,	/* Parser context */
>   	for (i = 0; i < pDest->nCol; i++) {
>   		Column *pDestCol = &pDest->aCol[i];
>   		Column *pSrcCol = &pSrc->aCol[i];
> -#ifdef SQLITE_ENABLE_HIDDEN_COLUMNS
> -		if ((pDestCol->colFlags | pSrcCol->colFlags) & COLFLAG_HIDDEN) {
> -			return 0;	/* Neither table may have __hidden__ columns */
> -		}
> -#endif
>   		if (pDestCol->affinity != pSrcCol->affinity) {
>   			return 0;	/* Affinity must be the same on all columns */
>   		}
> diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c
> index 1efc9ab7b..3eb3248c6 100644
> --- a/src/box/sql/pragma.c
> +++ b/src/box/sql/pragma.c
> @@ -345,7 +345,6 @@ sqlite3Pragma(Parse * pParse, Token * pId,	/* First part of [schema.]id field */
>   			pTab = sqlite3LocateTable(pParse, LOCATE_NOERR, zRight);
>   			if (pTab) {
>   				int i, k;
> -				int nHidden = 0;
>   				Column *pCol;
>   				Index *pPk = sqlite3PrimaryKeyIndex(pTab);
>   				pParse->nMem = 6;
> @@ -353,10 +352,6 @@ sqlite3Pragma(Parse * pParse, Token * pId,	/* First part of [schema.]id field */
>   				sqlite3ViewGetColumnNames(pParse, pTab);
>   				for (i = 0, pCol = pTab->aCol; i < pTab->nCol;
>   				     i++, pCol++) {
> -					if (IsHiddenColumn(pCol)) {
> -						nHidden++;
> -						continue;
> -					}
>   					if ((pCol->
>   					     colFlags & COLFLAG_PRIMKEY) == 0) {
>   						k = 0;
> @@ -372,8 +367,7 @@ sqlite3Pragma(Parse * pParse, Token * pId,	/* First part of [schema.]id field */
>   					assert(pCol->pDflt == 0
>   					       || pCol->pDflt->op == TK_SPAN);
>   					sqlite3VdbeMultiLoad(v, 1, "issisi",
> -							     i - nHidden,
> -							     pCol->zName,
> +							     i, pCol->zName,
>   							     sqlite3ColumnType
>   							     (pCol, ""),
>   							     pCol->
> diff --git a/src/box/sql/select.c b/src/box/sql/select.c
> index b86a9fa11..acc0a8ad9 100644
> --- a/src/box/sql/select.c
> +++ b/src/box/sql/select.c
> @@ -1946,7 +1946,6 @@ sqlite3ColumnsFromExprList(Parse * pParse,	/* Parsing context */
>   				sqlite3_randomness(sizeof(cnt), &cnt);
>   		}
>   		pCol->zName = zName;
> -		sqlite3ColumnPropertiesFromName(0, pCol);
>   		if (zName && sqlite3HashInsert(&ht, zName, pCol) == pCol) {
>   			sqlite3OomFault(db);
>   		}
> @@ -4949,19 +4948,6 @@ selectExpander(Walker * pWalker, Select * p)
>   									    zTName) == 0) {
>   							continue;
>   						}
> -
> -						/* If a column is marked as 'hidden', omit it from the expanded
> -						 * result-set list unless the SELECT has the SF_IncludeHidden
> -						 * bit set.
> -						 */
> -						if ((p->
> -						     selFlags &
> -						     SF_IncludeHidden) == 0
> -						    && IsHiddenColumn(&pTab->
> -								      aCol[j])
> -						    ) {
> -							continue;
> -						}
>   						tableSeen = 1;
>   
>   						if (i > 0 && zTName == 0) {
> diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h
> index 193c21c34..46b94430e 100644
> --- a/src/box/sql/sqliteInt.h
> +++ b/src/box/sql/sqliteInt.h
> @@ -1359,7 +1359,6 @@ struct Column {
>   /* Allowed values for Column.colFlags:
>    */
>   #define COLFLAG_PRIMKEY  0x0001	/* Column is part of the primary key */
> -#define COLFLAG_HIDDEN   0x0002	/* A hidden column. */
>   #define COLFLAG_HASTYPE  0x0004	/* Type name follows column name */
>   
>   /*
> @@ -1449,31 +1448,12 @@ struct Table {
>   
>   /*
>    * Allowed values for Table.tabFlags.
> - *
> - * TF_OOOHidden applies to tables or view that have hidden columns that are
> - * followed by non-hidden columns.Such tables require special
> - * handling during INSERT processing.
>    */
>   #define TF_Readonly        0x01	/* Read-only system table */
>   #define TF_Ephemeral       0x02	/* An ephemeral table */
>   #define TF_HasPrimaryKey   0x04	/* Table has a primary key */
>   #define TF_Autoincrement   0x08	/* Integer primary key is autoincrement */
>   #define TF_View   	   0x20	/* A view */
> -#define TF_OOOHidden       0x80	/* Out-of-Order hidden columns */
> -
> -/*
> - * Macros to determine if a column is hidden.
> - * IsOrdinaryHiddenColumn() is always false unless
> - * SQLITE_ENABLE_HIDDEN_COLUMNS is defined. The IsHiddenColumn()
> - * macro is general purpose.
> - */
> -#if defined(SQLITE_ENABLE_HIDDEN_COLUMNS)
> -#define IsHiddenColumn(X)         (((X)->colFlags & COLFLAG_HIDDEN)!=0)
> -#define IsOrdinaryHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0)
> -#else
> -#define IsHiddenColumn(X)         0
> -#define IsOrdinaryHiddenColumn(X) 0
> -#endif
>   
>   /*
>    * Each foreign key constraint is an instance of the following structure.
> @@ -2279,7 +2259,6 @@ struct Select {
>   #define SF_FixedLimit     0x04000	/* nSelectRow set by a constant LIMIT */
>   #define SF_MaybeConvert   0x08000	/* Need convertCompoundSelectToSubquery() */
>   #define SF_Converted      0x10000	/* By convertCompoundSelectToSubquery() */
> -#define SF_IncludeHidden  0x20000	/* Include hidden columns in output */
>   
>   /*
>    * The results of a SELECT can be distributed in several ways, as defined
> @@ -3127,11 +3106,6 @@ Table *sqlite3ResultSetOfSelect(Parse *, Select *);
>   Index *sqlite3PrimaryKeyIndex(Table *);
>   i16 sqlite3ColumnOfIndex(Index *, i16);
>   void sqlite3StartTable(Parse *, Token *, int);
> -#if SQLITE_ENABLE_HIDDEN_COLUMNS
> -void sqlite3ColumnPropertiesFromName(Table *, Column *);
> -#else
> -#define sqlite3ColumnPropertiesFromName(T,C)	/* no-op */
> -#endif
>   void sqlite3AddColumn(Parse *, Token *, Token *);
>   void sqlite3AddNotNull(Parse *, int);
>   void sqlite3AddPrimaryKey(Parse *, ExprList *, int, int, int);
> diff --git a/src/box/sql/whereexpr.c b/src/box/sql/whereexpr.c
> index 40c0431df..87972fd23 100644
> --- a/src/box/sql/whereexpr.c
> +++ b/src/box/sql/whereexpr.c
> @@ -1473,9 +1473,6 @@ sqlite3WhereExprAnalyze(SrcList * pTabList,	/* the FROM clause */
>   /*
>    * For table-valued-functions, transform the function arguments into
>    * new WHERE clause terms.
> - *
> - * Each function argument translates into an equality constraint against
> - * a HIDDEN column in the table.
>    */
>   void
>   sqlite3WhereTabFuncArgs(Parse * pParse,	/* Parsing context */
> @@ -1496,8 +1493,7 @@ sqlite3WhereTabFuncArgs(Parse * pParse,	/* Parsing context */
>   	if (pArgs == 0)
>   		return;
>   	for (j = k = 0; j < pArgs->nExpr; j++) {
> -		while (k < pTab->nCol
> -		       && (pTab->aCol[k].colFlags & COLFLAG_HIDDEN) == 0) {
> +		while (k < pTab->nCol) {
>   			k++;
>   		}
>   		if (k >= pTab->nCol) {




More information about the Tarantool-patches mailing list