1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-7563 Support CHECK constraint as in (or close to) SQL Standard

MDEV-10134 Add full support for DEFAULT

- Added support for using tables with MySQL 5.7 virtual fields,
  including MySQL 5.7 syntax
- Better error messages also for old cases
- CREATE ... SELECT now also updates timestamp columns
- Blob can now have default values
- Added new system variable "check_constraint_checks", to turn of
  CHECK constraint checking if needed.
- Removed some engine independent tests in suite vcol to only test myisam
- Moved some tests from 'include' to 't'. Should some day be done for all tests.
- FRM version increased to 11 if one uses virtual fields or constraints
- Changed to use a bitmap to check if a field has got a value, instead of
  setting HAS_EXPLICIT_VALUE bit in field flags
- Expressions can now be up to 65K in total
- Ensure we are not refering to uninitialized fields when handling virtual fields or defaults
- Changed check_vcol_func_processor() to return a bitmap of used types
- Had to change some functions that calculated cached value in fix_fields to do
  this in val() or getdate() instead.
- store_now_in_TIME() now takes a THD argument
- fill_record() now updates default values
- Add a lookahead for NOT NULL, to be able to handle DEFAULT 1+1 NOT NULL
- Automatically generate a name for constraints that doesn't have a name
- Added support for ALTER TABLE DROP CONSTRAINT
- Ensure that partition functions register virtual fields used. This fixes
  some bugs when using virtual fields in a partitioning function
This commit is contained in:
Michael Widenius
2016-06-29 09:14:22 +02:00
committed by Sergei Golubchik
parent 23d03a1b1e
commit db7edfed17
165 changed files with 5793 additions and 6325 deletions

View File

@ -1625,15 +1625,22 @@ static bool get_field_default_value(THD *thd, Field *field, String *def_value,
*/
has_now_default= field->has_insert_default_function();
has_default= (!(field->flags & NO_DEFAULT_VALUE_FLAG) &&
field->unireg_check != Field::NEXT_NUMBER &&
!((thd->variables.sql_mode & (MODE_MYSQL323 | MODE_MYSQL40))
&& has_now_default));
has_default= (field->default_value ||
(!(field->flags & NO_DEFAULT_VALUE_FLAG) &&
field->unireg_check != Field::NEXT_NUMBER &&
!((thd->variables.sql_mode & (MODE_MYSQL323 | MODE_MYSQL40))
&& has_now_default)));
def_value->length(0);
if (has_default)
{
if (has_now_default)
if (field->default_value)
{
def_value->set(field->default_value->expr_str.str,
field->default_value->expr_str.length,
system_charset_info);
}
else if (has_now_default)
{
def_value->append(STRING_WITH_LEN("CURRENT_TIMESTAMP"));
if (field->decimals() > 0)
@ -1922,6 +1929,13 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
!(sql_mode & MODE_NO_FIELD_OPTIONS))
packet->append(STRING_WITH_LEN(" AUTO_INCREMENT"));
}
if (field->check_constraint)
{
packet->append(STRING_WITH_LEN(" CHECK ("));
packet->append(field->check_constraint->expr_str.str,
field->check_constraint->expr_str.length);
packet->append(STRING_WITH_LEN(")"));
}
if (field->comment.length)
{
@ -2011,6 +2025,27 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
file->free_foreign_key_create_info(for_str);
}
/* Add table level check constraints */
if (share->table_check_constraints)
{
for (uint i= share->field_check_constraints;
i < share->table_check_constraints ; i++)
{
Virtual_column_info *check= table->check_constraints[i];
packet->append(STRING_WITH_LEN(",\n "));
if (check->name.length)
{
packet->append(STRING_WITH_LEN("CONSTRAINT "));
append_identifier(thd, packet, check->name.str, check->name.length);
}
packet->append(STRING_WITH_LEN(" CHECK ("));
packet->append(check->expr_str.str,
check->expr_str.length);
packet->append(STRING_WITH_LEN(")"));
}
}
packet->append(STRING_WITH_LEN("\n)"));
if (show_table_options)
{