diff --git a/dbcon/ddlpackage/ddl.l b/dbcon/ddlpackage/ddl.l index a6ab67d59..61741cb6b 100644 --- a/dbcon/ddlpackage/ddl.l +++ b/dbcon/ddlpackage/ddl.l @@ -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++;} diff --git a/dbcon/ddlpackage/ddl.y b/dbcon/ddlpackage/ddl.y index 510c7a3b0..34af1c593 100644 --- a/dbcon/ddlpackage/ddl.y +++ b/dbcon/ddlpackage/ddl.y @@ -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 DQ_IDENT IDENT FCONST SCONST CP_SEARCH_CONDITION_TEXT ICONST DATE TIME @@ -197,6 +200,8 @@ BOOL BOOLEAN MEDIUMINT TIMESTAMP BINARY %type opt_display_precision_scale_null %type opt_if_exists %type opt_if_not_exists +%type opt_signed +%type opt_zerofill %type trunc_table_statement %type rename_table_statement %type 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;} diff --git a/dbcon/ddlpackage/ddlpkg.cpp b/dbcon/ddlpackage/ddlpkg.cpp index ecf6264dc..90bfa45a9 100644 --- a/dbcon/ddlpackage/ddlpkg.cpp +++ b/dbcon/ddlpackage/ddlpkg.cpp @@ -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), diff --git a/utils/common/columnwidth.h b/utils/common/columnwidth.h new file mode 100644 index 000000000..dfcf767d4 --- /dev/null +++ b/utils/common/columnwidth.h @@ -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 diff --git a/utils/joiner/tuplejoiner.cpp b/utils/joiner/tuplejoiner.cpp index 30ad8c3dc..9dd6626c2 100644 --- a/utils/joiner/tuplejoiner.cpp +++ b/utils/joiner/tuplejoiner.cpp @@ -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::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(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) diff --git a/utils/joiner/tuplejoiner.h b/utils/joiner/tuplejoiner.h index b0d38364d..d91297845 100644 --- a/utils/joiner/tuplejoiner.h +++ b/utils/joiner/tuplejoiner.h @@ -39,6 +39,7 @@ #include "stlpoolallocator.h" #include "hasher.h" #include "threadpool.h" +#include "columnwidth.h" namespace joiner {