1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

MCOL-641 This commit adds support for SIGNED and ZEROFILL keywords in

CREATE TABLE. ZEROFILL is dummy though.

There is a new file with column width utilities.

Array access was replaced by a variable that is calculated only once in
TupleJoiner::updateCPData.
This commit is contained in:
drrtuy
2020-02-18 11:55:51 +03:00
committed by Roman Nozdrin
parent 93170c3b31
commit 2eb5af1d24
6 changed files with 115 additions and 58 deletions

View File

@ -156,6 +156,7 @@ REFERENCES {return REFERENCES;}
RENAME {return RENAME;}
RESTRICT {return RESTRICT;}
SESSION_USER {return SESSION_USER;}
SIGNED {return SIGNED;}
SYSTEM_USER {return SYSTEM_USER;}
SET {return SET;}
SMALLINT {return SMALLINT;}
@ -189,6 +190,7 @@ BOOL {return BOOL;}
BOOLEAN {return BOOLEAN;}
MEDIUMINT {return MEDIUMINT;}
BINARY {return BINARY;}
ZEROFILL {return ZEROFILL;}
\n { lineno++;}

View File

@ -63,6 +63,7 @@ char* copy_string(const char *str);
%pure-parser
%lex-param {void * scanner}
%parse-param {struct ddlpackage::pass_to_bison * x}
%debug
/* Bison uses this to generate a C union definition. This is used to
store the application created values associated with syntactic
@ -104,15 +105,17 @@ char* copy_string(const char *str);
%token ACTION ADD ALTER AUTO_INCREMENT BIGINT BIT BLOB IDB_BLOB CASCADE IDB_CHAR
CHARACTER CHECK CLOB COLUMN
BOOL BOOLEAN BINARY
COLUMNS COMMENT CONSTRAINT CONSTRAINTS CREATE CURRENT_USER DATETIME DEC
DECIMAL DEFAULT DEFERRABLE DEFERRED IDB_DELETE DROP ENGINE
FOREIGN FULL IMMEDIATE INDEX INITIALLY IDB_INT INTEGER KEY LONGBLOB LONGTEXT
MATCH MAX_ROWS MEDIUMBLOB MEDIUMTEXT
MATCH MAX_ROWS MEDIUMBLOB MEDIUMTEXT MEDIUMINT
MIN_ROWS MODIFY NO NOT NULL_TOK NUMBER NUMERIC ON PARTIAL PRECISION PRIMARY
REFERENCES RENAME RESTRICT SET SMALLINT TABLE TEXT TINYBLOB TINYTEXT
TINYINT TO UNIQUE UNSIGNED UPDATE USER SESSION_USER SYSTEM_USER VARCHAR VARBINARY
TINYINT TO UNIQUE UNSIGNED UPDATE USER SESSION_USER SIGNED SYSTEM_USER VARCHAR VARBINARY
VARYING WITH ZONE DOUBLE IDB_FLOAT REAL CHARSET COLLATE IDB_IF EXISTS CHANGE TRUNCATE
BOOL BOOLEAN MEDIUMINT TIMESTAMP BINARY
TIMESTAMP
ZEROFILL
%token <str> DQ_IDENT IDENT FCONST SCONST CP_SEARCH_CONDITION_TEXT ICONST DATE TIME
@ -197,6 +200,8 @@ BOOL BOOLEAN MEDIUMINT TIMESTAMP BINARY
%type <str> opt_display_precision_scale_null
%type <str> opt_if_exists
%type <str> opt_if_not_exists
%type <str> opt_signed
%type <str> opt_zerofill
%type <sqlStmt> trunc_table_statement
%type <sqlStmt> rename_table_statement
%type <str> ident
@ -1002,16 +1007,14 @@ exact_numeric_type:
$2->fLength = DDLDatatypeLength[DDL_UNSIGNED_NUMERIC];
$$ = $2;
}
| DECIMAL opt_precision_scale
| DECIMAL opt_precision_scale opt_signed opt_zerofill
{
$2->fType = DDL_DECIMAL;
/* $2->fLength = DDLDatatypeLength[DDL_DECIMAL]; */
$$ = $2;
}
| DECIMAL opt_precision_scale UNSIGNED
| DECIMAL opt_precision_scale UNSIGNED opt_zerofill
{
$2->fType = DDL_UNSIGNED_DECIMAL;
/* $3->fLength = DDLDatatypeLength[DDL_DECIMAL]; */
$$ = $2;
}
| NUMBER opt_precision_scale
@ -1106,6 +1109,14 @@ opt_precision_scale:
| {$$ = new ColumnType(10,0);}
;
opt_signed:
SIGNED {$$ = NULL;}
| {$$ = NULL;}
opt_zerofill:
ZEROFILL {$$ = NULL;}
| {$$ = NULL;}
opt_display_width:
'(' ICONST ')' {$$ = NULL;}
| {$$ = NULL;}

View File

@ -26,6 +26,7 @@
#define DDLPKG_DLLEXPORT
#include "ddlpkg.h"
#undef DDLPKG_DLLEXPORT
#include "../../utils/common/columnwidth.h"
namespace ddlpackage
{
@ -61,32 +62,6 @@ ostream& operator<<(ostream& os, const QualifiedName& qname)
return os;
}
/** @brief Map a DECIMAL precision to data width in bytes */
unsigned int precision_width(unsigned p)
{
switch (p)
{
case 1:
case 2:
return 1;
case 3:
case 4:
return 2;
case 5:
case 6:
case 7:
case 8:
case 9:
return 4;
default:
return 8;
}
}
ColumnType::ColumnType(int prec, int scale) :
fType(DDL_INVALID_DATATYPE),
fLength(0),
@ -94,7 +69,7 @@ ColumnType::ColumnType(int prec, int scale) :
fScale(scale),
fWithTimezone(false)
{
fLength = precision_width(fPrecision);
fLength = utils::widthByPrecision(fPrecision);
}
ColumnType::ColumnType(int type) :
@ -141,19 +116,6 @@ ColumnType::ColumnType(int type) :
break;
}
}
#if 0
ColumnType::ColumnType(int type, int length, int precision, int scale, int compressiontype, const char* autoIncrement, int64_t nextValue, bool withTimezone) :
fType(type),
fLength(length),
fPrecision(precision),
fScale(scale),
fWithTimezone(withTimezone),
fCompressiontype(compressiontype),
fAutoincrement(autoIncrement),
fNextvalue(nextValue)
{
}
#endif
ColumnConstraintDef::ColumnConstraintDef(DDL_CONSTRAINTS type) :
SchemaObject(),
fDeferrable(false),

View File

@ -0,0 +1,74 @@
/* Copyright (C) 2020 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of
the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
#ifndef UTILS_COLWIDTH_H
#define UTILS_COLWIDTH_H
#define MAXLEGACYWIDTH 8
namespace utils
{
inline bool isWide(uint8_t width)
{
return width > MAXLEGACYWIDTH;
}
inline bool isNarrow(uint8_t width)
{
return width <= MAXLEGACYWIDTH;
}
// WIP MCOL-641 Replace with template
/** @brief Map a DECIMAL precision to data width in bytes */
inline uint8_t widthByPrecision(unsigned p)
{
switch (p)
{
case 1:
case 2:
return 1;
case 3:
case 4:
return 2;
case 5:
case 6:
case 7:
case 8:
case 9:
return 4;
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
return 8;
default:
return 16;
}
}
}
#endif // UTILS_COLWIDTH_H

View File

@ -1070,15 +1070,15 @@ void TupleJoiner::updateCPData(const Row& r)
for (col = 0; col < smallKeyColumns.size(); col++)
{
// if (r.getColumnWidth(smallKeyColumns[col]) > 8)
if (r.isLongString(smallKeyColumns[col]))
auto colIdx = smallKeyColumns[col];
if (r.isLongString(colIdx))
continue;
int64_t& min = cpValues[col][0], &max = cpValues[col][1];
auto& min = cpValues[col][0], &max = cpValues[col][1];
if (r.isCharType(smallKeyColumns[col]))
if (r.isCharType(colIdx))
{
int64_t val = r.getIntField(smallKeyColumns[col]);
int64_t val = r.getIntField(colIdx);
if (order_swap(val) < order_swap(min) ||
min == numeric_limits<int64_t>::max())
@ -1092,10 +1092,10 @@ void TupleJoiner::updateCPData(const Row& r)
max = val;
}
}
else if (r.isUnsigned(smallKeyColumns[col]))
else if (r.isUnsigned(colIdx))
{
uint64_t uval;
if (r.getColType(smallKeyColumns[col]) == CalpontSystemCatalog::LONGDOUBLE)
if (r.getColType(colIdx) == CalpontSystemCatalog::LONGDOUBLE)
{
double dval = (double)roundl(r.getLongDoubleField(smallKeyColumns[col]));
switch (largeRG.getColType(largeKeyColumns[col]))
@ -1116,7 +1116,7 @@ void TupleJoiner::updateCPData(const Row& r)
}
else
{
uval = r.getUintField(smallKeyColumns[col]);
uval = r.getUintField(colIdx);
}
if (uval > static_cast<uint64_t>(max))
@ -1128,9 +1128,9 @@ void TupleJoiner::updateCPData(const Row& r)
else
{
int64_t val;
if (r.getColType(smallKeyColumns[col]) == CalpontSystemCatalog::LONGDOUBLE)
if (r.getColType(colIdx) == CalpontSystemCatalog::LONGDOUBLE)
{
double dval = (double)roundl(r.getLongDoubleField(smallKeyColumns[col]));
double dval = (double)roundl(r.getLongDoubleField(colIdx));
switch (largeRG.getColType(largeKeyColumns[col]))
{
case CalpontSystemCatalog::DOUBLE:
@ -1147,9 +1147,16 @@ void TupleJoiner::updateCPData(const Row& r)
}
}
}
else if (utils::isWide(r.getColumnWidth(colIdx))
&& (r.getColType(colIdx) == CalpontSystemCatalog::DECIMAL
|| r.getColType(colIdx) == CalpontSystemCatalog::UDECIMAL))
{
// WIP MCOL-641
}
else
{
val = r.getIntField(smallKeyColumns[col]);
val = r.getIntField(colIdx);
}
if (val > max)

View File

@ -39,6 +39,7 @@
#include "stlpoolallocator.h"
#include "hasher.h"
#include "threadpool.h"
#include "columnwidth.h"
namespace joiner
{