summaryrefslogtreecommitdiff
path: root/sql/item_func.cc
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2017-12-22 14:56:09 +0200
committerMonty <monty@mariadb.org>2017-12-22 14:56:58 +0200
commit9cc7789e9084e7d59a43f9560870e496843535f9 (patch)
tree71f18d4ae038bb59019a7812b22778500b6a8c0c /sql/item_func.cc
parent5b4c8469d5e1988f6f7408fa6c7cc54f9bb1f290 (diff)
downloadmariadb-git-9cc7789e9084e7d59a43f9560870e496843535f9.tar.gz
MDEV 13679 Enabled sequences to be used in DEFAULT
Other changes done to get this to work: - Added 'internal_tables' to TABLE object to list which sequence tables is needed to use the table. - Mark any expression using DEFAULT() with LEX->default_used. This is needed when deciding if we should open internal sequence tables when a table is opened (we don't need to open sequence tables if the main table is only used with SELECT). - Create_and_open_temporary_table() can now also open all internal sequence tables. - Added option MYSQL_LOCK_USE_MALLOC to mysql_lock_tables() to force memory allocation to be used with malloc instead of memroot. - Added flag to MYSQL_LOCK to remember if allocation was done with malloc or memroot (makes code simpler and safer). - init_one_table_for_prelocking() now takes argument for what lock to use instead of it's a routine or something else. - Renamed prelocking placeholders to make them more understandable as they are now used in more code. - Changed test in check_lock_and_start_stmt() if found table has correct locks. The old test didn't work for tables that has lock TL_WRITE_ALLOW_WRITE, which is what sequence tables are using. - Added VCOL_NOT_VIRTUAL option to ensure that sequence functions can't be used with virtual columns - More sequence tests
Diffstat (limited to 'sql/item_func.cc')
-rw-r--r--sql/item_func.cc40
1 files changed, 30 insertions, 10 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 55d141b9968..ac7ed75e7f9 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -6686,14 +6686,22 @@ longlong Item_func_nextval::val_int()
longlong value;
int error;
const char *key;
- TABLE *table= table_list->table;
uint length= get_table_def_key(table_list, &key);
- THD *thd= table->in_use;
+ THD *thd;
SEQUENCE_LAST_VALUE *entry;
char buff[80];
String key_buff(buff,sizeof(buff), &my_charset_bin);
- DBUG_ASSERT(table && table->s->sequence);
DBUG_ENTER("Item_func_nextval::val_int");
+ update_table();
+ DBUG_ASSERT(table && table->s->sequence);
+ thd= table->in_use;
+
+ if (thd->count_cuted_fields == CHECK_FIELD_EXPRESSION)
+ {
+ /* Alter table checking if function works */
+ null_value= 0;
+ DBUG_RETURN(0);
+ }
if (table->s->tmp_table != NO_TMP_TABLE)
{
@@ -6745,7 +6753,7 @@ void Item_func_nextval::print(String *str, enum_query_type query_type)
char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
const char *d_name= table_list->db, *t_name= table_list->table_name;
bool use_db_name= d_name && d_name[0];
- THD *thd= current_thd;
+ THD *thd= current_thd; // Don't trust 'table'
str->append(func_name());
str->append('(');
@@ -6785,12 +6793,14 @@ longlong Item_func_lastval::val_int()
const char *key;
SEQUENCE_LAST_VALUE *entry;
uint length= get_table_def_key(table_list, &key);
- THD *thd= table_list->table->in_use;
+ THD *thd;
char buff[80];
String key_buff(buff,sizeof(buff), &my_charset_bin);
DBUG_ENTER("Item_func_lastval::val_int");
+ update_table();
+ thd= table->in_use;
- if (table_list->table->s->tmp_table != NO_TMP_TABLE)
+ if (table->s->tmp_table != NO_TMP_TABLE)
{
/*
Temporary tables has an extra \0 at end to distinguish it from
@@ -6809,7 +6819,7 @@ longlong Item_func_lastval::val_int()
null_value= 1;
DBUG_RETURN(0);
}
- if (entry->check_version(table_list->table))
+ if (entry->check_version(table))
{
/* Table droped and re-created, remove current version */
my_hash_delete(&thd->sequences, (uchar*) entry);
@@ -6834,10 +6844,20 @@ longlong Item_func_setval::val_int()
{
longlong value;
int error;
- TABLE *table= table_list->table;
- DBUG_ASSERT(table && table->s->sequence);
+ THD *thd;
DBUG_ENTER("Item_func_setval::val_int");
+ update_table();
+ DBUG_ASSERT(table && table->s->sequence);
+ thd= table->in_use;
+
+ if (thd->count_cuted_fields == CHECK_FIELD_EXPRESSION)
+ {
+ /* Alter table checking if function works */
+ null_value= 0;
+ DBUG_RETURN(0);
+ }
+
value= nextval;
error= table->s->sequence->set_value(table, nextval, round, is_used);
if (error)
@@ -6856,7 +6876,7 @@ void Item_func_setval::print(String *str, enum_query_type query_type)
char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
const char *d_name= table_list->db, *t_name= table_list->table_name;
bool use_db_name= d_name && d_name[0];
- THD *thd= table_list->table->in_use;
+ THD *thd= current_thd; // Don't trust 'table'
str->append(func_name());
str->append('(');