Commit graph

63 commits

Author SHA1 Message Date
Alexander Barkov
ac53b49b1b Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-05-05 16:12:54 +04:00
Jacob Mathew
0b52b28b91 MDEV-10355 Weird error message upon CREATE TABLE with DEFAULT
Fixed handling of default values with cached temporal functions so that the
CREATE TABLE statement now succeeds.
Fixed virtual column session cleanup.
Fixed the error message.
Added quoting of date/time values in cases when this was omitted.
Added a test case in default.test.
Updated test result files.
2017-04-18 17:36:05 -07:00
Alexander Barkov
fb43180c4f Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-03-29 07:24:05 +04:00
Sergei Golubchik
f63007a371 MDEV-10354 Assertion `! is_set()' failed in Diagnostics_area::set_ok_status on CREATE TABLE with invalid default
test case
2017-03-29 00:40:22 +02:00
Sergei Golubchik
7a1b0582d6 MDEV-11114 Cannot drop column referenced by CHECK constraint: Unknown column 'a' in 'virtual column function'
clarify the error message
2017-03-29 00:40:21 +02:00
Alexander Barkov
47b7ffb396 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-02-27 10:07:59 +04:00
Sergei Golubchik
d2f84ab978 MDEV-10352 Server crashes in Field::set_default on CREATE TABLE
fix Item_default_value not to pretend being const_item
if the field's default_value expression isn't parsed yet
2017-02-13 18:12:04 +01:00
Sergei Golubchik
cd4dd2b62d MDEV-10201 Bad results for CREATE TABLE t1 (a INT DEFAULT b, b INT DEFAULT 4)
Optionally do table->update_default_fields() even for INSERT
that supposedly provides values for all column. Because these
"values" might be DEFAULT, which would need table->update_default_fields()
at the end.

Also set Item_default_value::used_tables() from the default expression.
Non-zero used_field() means that mysql_insert() will initialize all
fields to their default values (with restore_record()) even if
all columns are later provided with values. Because default expressions
may refer to other columns and they must be initialized.
2017-02-13 18:12:04 +01:00
Nirbhay Choubey
8b2e642aa2 MDEV-7635: Update tests to adapt to the new default sql_mode 2017-02-10 06:30:42 -05:00
Alexander Barkov
d333e3ad9c Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-02-02 08:21:42 +04:00
Alexander Barkov
45e40892c5 MDEV-11134 Assertion `fixed' failed in Item::const_charset_converter(THD*, CHARSET_INFO*, bool, const char*)
Problem: Item_param::basic_const_item() returned true when fixed==false.
This unexpected combination made Item::const_charset_converter() crash
on asserts.

Fix:
- Changing all Item_param::set_xxx() to set "fixed" to true.
  This fixes the problem.
- Additionally, changing all Item_param::set_xxx() to set
  Item_param::item_type, to avoid duplicate code, and for consistency,
  to make the code symmetric between different constant types.
  Before this patch only set_null() set item_type.
- Moving Item_param::state and Item_param::item_type from public to private,
  to make sure easier that these members are in sync with "fixed" and to
  each other.
- Adding a new argument "unsigned_arg" to Item::set_decimal(),
  and reusing it in two places instead of duplicate code.
- Adding a new method Item_param::fix_temporal() and reusing it in two places.
- Adding methods has_no_value(), has_long_data_value(), has_int_value(),
  instead of direct access to Item_param::state.
2017-01-23 22:25:29 +04:00
Alexander Barkov
095ea087b4 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-01-17 18:25:18 +04:00
Monty
ea1b25046c New simpler bugfix for UPDATE and virtual BLOBs
When updating a table with virtual BLOB columns, the following might
happen:
- an old record is read from the table, it has no virtual blob values
- update_virtual_fields() is run, vcol blob gets its value into the
  record. But only a pointer to the value is in the table->record[0],
  the value is in Field_blob::value String (but it doesn't have to be!
  it can be in the record, if the column is just a copy of another
  columns: ... b VARCHAR, c BLOB AS (b) ...)
- store_record(table,record[1]), old record now is in record[1]
- fill_record() prepares new values in record[0], vcol blob is updated,
  new value replaces the old one in the Field_blob::value
- now both record[1] and record[0] have a pointer that points to the
  *new* vcol blob value. Or record[1] has a pointer to nowhere if
   Field_blob::value had to realloc.

To fix this I have introduced a new String object 'read_value' in
Field_blob.  When updating virtual columns when a row has been read,
the allocated value is stored in 'read_value' instead of 'value'.  The
allocated blobs for the new row is stored in 'value' as before.

I also made, as a safety precaution, the insert delayed handling of
blobs more general by using value to store strings instead of the
record.  This ensures that virtual functions on delayed insert should
work in as in the case of normal insert.

Triggers are now properly updating the read, write and vcol maps for used
fields. This means that we don't need VCOL_UPDATE_FOR_READ_WRITE anymore
and there is no need for any other special handling of triggers in
update_virtual_fields().

To be able to test how many times virtual fields are invoked, I also
relaxed rules that one can use local (@) variables in DEFAULT and non
persistent virtual field expressions.
2017-01-11 09:18:35 +02:00
Alexander Barkov
b6aa3d2add Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2016-12-30 13:55:47 +04:00
Sergei Golubchik
4a5d25c338 Merge branch '10.1' into 10.2 2016-12-29 13:23:18 +01:00
Alexander Barkov
cb16d753b2 MDEV-11337 Split Item::save_in_field() into virtual methods in Type_handler
Also fixes:
MDEV-11331 Wrong result for INSERT INTO t1 (datetime_field) VALUES (hybrid_function_of_TIME_data_type)
MDEV-11333 Expect "Impossible where condition" for WHERE timestamp_field>=DATE_ADD(TIMESTAMP'9999-01-01 00:00:00',INTERVAL 1000 YEAR)

This patch does the following:
1. Splits the function Item::save_in_field() into pieces:
- Item::save_str_in_field()
- Item::save_real_in_field()
- Item::save_decimal_in_field()
- Item::save_int_in_field()

2. Adds the missing "no_conversion" parameters to
   Item::save_time_in_field() and Item::save_date_in_field(),
   so this parameter is now correctly passed to
   set_field_to_null_with_conversions().
   This fixes the problem reported in 11333.

3. Introduces a new virtual method Type_handler::Item_save_in_field()
   and uses the methods Item::save_xxx_in_field() from the implementations
   of Type_handler_xxx::Item_save_in_field().

These changes additionally fix the problem reported in MDEV-11331,
as the old code erroneously handled expressions like
COALESE(datetime-expression) through the STRING_RESULT branch of
Item::save_in_field() and therefore they looked like string type expressions
for the target fields. Now such expressions are correctly handled by
Item::save_date_in_field().
2016-12-16 18:23:20 +04:00
Sergei Golubchik
180065ebb0 Item::print(): remove redundant parentheses
by introducing new Item::precedence() method and using it
to decide whether parentheses are required
2016-12-12 20:44:41 +01:00
Sergei Golubchik
a411d7f4f6 store/show vcols as item->print()
otherwise we'd need to store sql_mode *per vcol*
(consider CREATE INDEX...) and how SHOW CREATE TABLE would
support that?

Additionally, get rid of vcol::expr_str, just to make sure
the string is always generated and never leaked in the
original form.
2016-12-12 20:35:41 +01:00
Sergei Golubchik
2f20d297f8 Merge branch '10.0' into 10.1 2016-12-11 09:53:42 +01:00
Oleksandr Byelkin
098dff10ba MDEV-11359 Implement IGNORE for bulk operation 2016-11-29 08:29:46 +01:00
Alexander Barkov
1d9b043a1f A join patch for MDEV-10780 and MDEV-11265
MDEV-10780 Server crashes in in create_tmp_table
MDEV-11265 Access defied when CREATE VIIEW v1 AS SELECT DEFAULT(column) FROM t1

Item_default_value and Item_insert_value erroneously derive from Item_field
but forgot to override some methods that apply only to true fields,
so the server code mixes Item_{default|insert}_value instances with real
table fields (i.e. true Item_field) in some cases.
Overriding a few methods to avoid this.

TODO: we should eventually derive Item_default_value (and Item_insert_value)
directly from Item, as they don't really need the entire Item_field,
Item_ident and Item_result_field functionality.
Only the member "Field *field" related functionality is actually needed,
like val_xxx(), is_null(), get_geometry_type(), charset_for_protocol(), etc.
2016-11-10 18:15:36 +04:00
Sergei Golubchik
12d2c4fcd0 optimize constant default expressions
to be calculated at the CREATE TABLE time and stored in
the default row image.
2016-08-27 16:59:12 +02:00
Sergei Golubchik
4070d55735 fix: CHECK and DEFAULT after CREATE ... SELECT
expression defaults and check constraints should behave as
constant default values - copied from fields, not copied from expressions
2016-08-27 16:59:12 +02:00
Sergei Golubchik
266563ad77 fix: CREATE TABLE (col TIMESTAMP(6) DEFAULT NOW(2))
That is, when the precision of DEFAULT NOW() is less than
the precision of the column, do not convert it to unireg_check,
use the new approach where DEFAULT is tryly an expression.
2016-08-27 16:59:12 +02:00
Sergei Golubchik
73a220aac3 session-state dependent functions in DEFAULT/CHECK/vcols
* revert part of the db7edfe that moved calculations from
  fix_fields to val_str for Item_func_sysconst and descendants
* mark session state dependent functions in check_vcol_func_processor()
* re-run fix_fields for all such functions for every statement
* fix CURRENT_USER/CURRENT_ROLE not to use Name_resolution_context
  (that is allocated on the stack in unpack_vcol_info_from_frm())

Note that NOW(), CURDATE(), etc use lazy initialization and do *not*
force fix_fields to be re-run. The rule is:
* lazy initialization is *not* allowed, if it changes metadata (so,
   e.g. DAYNAME() cannot use it)
* lazy initialization is *preferrable* if it has side effects (e.g.
  NOW() sets thd->time_zone_used=1, so it's better to do it when
  the value of NOW is actually needed, not when NOW is simply prepared)
2016-08-27 16:59:12 +02:00
Sergei Golubchik
6820bf9ca9 do not quote numbers in the DEFAULT clause in SHOW CREATE 2016-08-27 16:59:11 +02:00
Sergei Golubchik
80de816df0 test for ALTER TABLE ... SET DEFAULT 2016-06-30 11:43:02 +02:00
Sergei Golubchik
3687edeec9 clarify the order of evaluation for INSERT 2016-06-30 11:43:02 +02:00
Sergei Golubchik
5f22379fc8 fix for CREATE ... ( ... DEFAULT const_expr ... )
make it return same errors on CREATE as

CREATE ... ( ... DEFAULT const ... )
2016-06-30 11:43:02 +02:00
Sergei Golubchik
0a056c9b53 better ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED 2016-06-30 11:43:02 +02:00
Sergei Golubchik
1b4f0962c1 fix grammar for "DEFAULT (SELECT 1)" not be a syntax error
the error should be "subselect is not allowed here", same as for
DEFAULT ((SELECT 1))
2016-06-30 11:43:02 +02:00
Sergei Golubchik
e8bdb73ade function DEFAULT(x) now works for expression defaults 2016-06-30 11:43:02 +02:00
Sergei Golubchik
3205da7124 cleanup default.test 2016-06-30 11:43:02 +02:00
Alexander Barkov
4dcbb775ae parentheses in default
- Adding SHOW CREATE TABLE into all DEFAULT tests,
  to cover need_parentheses_in_default() for all items
- Fixing a few items not to print parentheses in DEFAULT:
  spatial function-alike predicates, IS_IPV4 and IS_IPV6 functions,
  COLUMN_CHECK() and COLUMN_EXISTS().
2016-06-30 11:43:02 +02:00
Michael Widenius
fb67cde237 Use default character set for expressions
- Force usage of () around complex DEFAULT expressions
- Give error if DEFAULT expression contains invalid characters
- Don't use const_charset_conversion for stored Item_func_sysconf expressions
  as the result is not constaint over different executions
- Fixed Item_func_user() to not store calculated value in str_value
2016-06-30 11:43:02 +02:00
Alexander Barkov
8f226121e5 More test for MDEV-10134 Add full support for DEFAULT
ENCRYPT(), SHA(), SHA2(),
AES_ENCRYPT(), AES_DECRYPT(),
DES_ENCRYPT(), DES_DECRYPT()
2016-06-30 11:43:02 +02:00
Alexander Barkov
ca8950cc11 More test for MDEV-10134 Add full support for DEFAULT
CRC32(), MD5(), FROM_BASE64(), TO_BASE64(), HEX(), UNHEX(),
ENCODE(), DECODE(), PASSWORD(),
COMPRESS(), UNCOMPRESS(), UNCOMPRESSED_LENGTH().
2016-06-30 11:43:02 +02:00
Alexander Barkov
f9cdc74851 More test for MDEV-10134 Add full support for DEFAULT
UUID(), UUID_SHORT()
2016-06-30 11:43:02 +02:00
Alexander Barkov
6c626117e7 More test for MDEV-10134 Add full support for DEFAULT
Miscelaneous functions:
BENCHMARK(), SLEEP(), ROW_COUNT(), FOUND_ROWS(),
GET_LOCK(), RELEASE_LOCK(), IS_USED_LOCK(), IS_FREE_LOCK(),
MASTER_POS_WAIT(), MASTER_GTID_WAIT(), BINLOG_GTID_POS(),
ST_GIS_DEBUG(), DECODE_HISTOGRAM(),
2016-06-30 11:43:02 +02:00
Alexander Barkov
2654eabbe0 More test for MDEV-10134 Add full support for DEFAULT
Miscelaneous functions:
LIKE_RANGE_MIN(), LIKE_RANGE_MAX(), WEIGHT_STRING(),
GET_FORMAT(), FORMAT(), LOAD_FILE().
2016-06-30 11:43:02 +02:00
Alexander Barkov
111c0f1423 More test for MDEV-10134 Add full support for DEFAULT
Metadata functions
2016-06-30 11:43:02 +02:00
Alexander Barkov
b5870a5dd3 More test for MDEV-10134 Add full support for DEFAULT
Functions DATABASE() and USER().
2016-06-30 11:43:02 +02:00
Alexander Barkov
6cb4731fdf More test for MDEV-10134 Add full support for DEFAULT
- INT result functions
- CAST variants: COLLATE, BINARY, CONVERT(..USING)
2016-06-30 11:43:02 +02:00
Alexander Barkov
582ee3973e More tests for MDEV-10134 Add full support for DEFAULT
Numeric functions with string input
2016-06-30 11:43:02 +02:00
Alexander Barkov
f9fb646b16 More tests for MDEV-10134 Add full support for DEFAULT
Boolean predicates
2016-06-30 11:43:02 +02:00
Alexander Barkov
11ff9014b1 More tests for MDEV-7563 Support CHECK constraint
Adding tests for cast, bit functions, string functions.
2016-06-30 11:43:02 +02:00
Alexander Barkov
11debf698f Adding more tests for "MDEV-7563 Support CHECK constraint":
- real functions
- temporal functions
- hybrid functions
2016-06-30 11:43:02 +02:00
Michael Widenius
db7edfed17 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
2016-06-30 11:43:02 +02:00
Michael Widenius
6c173324ff Part of MDEV-10134 Add full support for DEFAULT
Print default values for BLOB's.
This is a part commit for automatic changes to make the real commit smaller.
All changes here are related to that we now print DEFAULT NULL for blob and
text fields, like we do for all other fields.
2016-06-30 11:43:02 +02:00
Oleksandr Byelkin
e3982cead2 MDEV-6066: Merge new defaults from 5.6 and 5.7 (defaults changed, QC can be stopped with no-zero size) 2015-09-04 10:33:56 +02:00