Merge branch '10.4' into bb-10.4-mdev16188
This commit is contained in:
commit
28f18aa7a6
@ -110,6 +110,7 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
|
|||||||
../sql/sql_analyze_stmt.cc ../sql/sql_analyze_stmt.h
|
../sql/sql_analyze_stmt.cc ../sql/sql_analyze_stmt.h
|
||||||
../sql/compat56.cc
|
../sql/compat56.cc
|
||||||
../sql/sql_type.cc ../sql/sql_type.h
|
../sql/sql_type.cc ../sql/sql_type.h
|
||||||
|
../sql/sql_type_json.cc
|
||||||
../sql/table_cache.cc ../sql/mf_iocache_encr.cc
|
../sql/table_cache.cc ../sql/mf_iocache_encr.cc
|
||||||
../sql/item_inetfunc.cc
|
../sql/item_inetfunc.cc
|
||||||
../sql/wsrep_dummy.cc ../sql/encryption.cc
|
../sql/wsrep_dummy.cc ../sql/encryption.cc
|
||||||
|
@ -132,7 +132,7 @@ SET (SQL_SOURCE
|
|||||||
rpl_gtid.cc rpl_parallel.cc
|
rpl_gtid.cc rpl_parallel.cc
|
||||||
semisync.cc semisync_master.cc semisync_slave.cc
|
semisync.cc semisync_master.cc semisync_slave.cc
|
||||||
semisync_master_ack_receiver.cc
|
semisync_master_ack_receiver.cc
|
||||||
sql_type.cc
|
sql_type.cc sql_type_json.cc
|
||||||
item_windowfunc.cc sql_window.cc
|
item_windowfunc.cc sql_window.cc
|
||||||
sql_cte.cc
|
sql_cte.cc
|
||||||
item_vers.cc
|
item_vers.cc
|
||||||
|
12
sql/field.cc
12
sql/field.cc
@ -10501,6 +10501,13 @@ bool Column_definition::fix_attributes_temporal_with_time(uint int_part_length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Column_definition::validate_check_constraint(THD *thd)
|
||||||
|
{
|
||||||
|
return check_constraint &&
|
||||||
|
check_expression(check_constraint, &field_name, VCOL_CHECK_FIELD);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Column_definition::check(THD *thd)
|
bool Column_definition::check(THD *thd)
|
||||||
{
|
{
|
||||||
DBUG_ENTER("Column_definition::check");
|
DBUG_ENTER("Column_definition::check");
|
||||||
@ -10515,9 +10522,8 @@ bool Column_definition::check(THD *thd)
|
|||||||
DBUG_RETURN(TRUE);
|
DBUG_RETURN(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (check_constraint &&
|
if (type_handler()->Column_definition_validate_check_constraint(thd, this))
|
||||||
check_expression(check_constraint, &field_name, VCOL_CHECK_FIELD))
|
DBUG_RETURN(TRUE);
|
||||||
DBUG_RETURN(1);
|
|
||||||
|
|
||||||
if (default_value)
|
if (default_value)
|
||||||
{
|
{
|
||||||
|
@ -4675,6 +4675,7 @@ public:
|
|||||||
bool fix_attributes_bit();
|
bool fix_attributes_bit();
|
||||||
|
|
||||||
bool check(THD *thd);
|
bool check(THD *thd);
|
||||||
|
bool validate_check_constraint(THD *thd);
|
||||||
|
|
||||||
bool stored_in_db() const { return !vcol_info || vcol_info->stored_in_db; }
|
bool stored_in_db() const { return !vcol_info || vcol_info->stored_in_db; }
|
||||||
|
|
||||||
|
@ -9587,21 +9587,3 @@ bool LEX::sp_proc_stmt_statement_finalize(THD *thd, bool no_lookahead)
|
|||||||
lip->get_tok_start());
|
lip->get_tok_start());
|
||||||
return LEX::sp_proc_stmt_statement_finalize_buf(thd, qbuf);
|
return LEX::sp_proc_stmt_statement_finalize_buf(thd, qbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Create JSON_VALID(field_name) expression
|
|
||||||
*/
|
|
||||||
|
|
||||||
Virtual_column_info *make_json_valid_expr(THD *thd, LEX_CSTRING *field_name)
|
|
||||||
{
|
|
||||||
Lex_ident_sys_st str;
|
|
||||||
Item *field, *expr;
|
|
||||||
str.set_valid_utf8(field_name);
|
|
||||||
if (unlikely(!(field= thd->lex->create_item_ident_field(thd, NullS, NullS,
|
|
||||||
&str))))
|
|
||||||
return 0;
|
|
||||||
if (unlikely(!(expr= new (thd->mem_root) Item_func_json_valid(thd, field))))
|
|
||||||
return 0;
|
|
||||||
return add_virtual_expression(thd, expr);
|
|
||||||
}
|
|
||||||
|
@ -148,7 +148,7 @@ public:
|
|||||||
bool copy_or_convert(THD *thd, const Lex_ident_cli_st *str, CHARSET_INFO *cs);
|
bool copy_or_convert(THD *thd, const Lex_ident_cli_st *str, CHARSET_INFO *cs);
|
||||||
bool is_null() const { return str == NULL; }
|
bool is_null() const { return str == NULL; }
|
||||||
bool to_size_number(ulonglong *to) const;
|
bool to_size_number(ulonglong *to) const;
|
||||||
void set_valid_utf8(LEX_CSTRING *name)
|
void set_valid_utf8(const LEX_CSTRING *name)
|
||||||
{
|
{
|
||||||
DBUG_ASSERT(Well_formed_prefix(system_charset_info, name->str,
|
DBUG_ASSERT(Well_formed_prefix(system_charset_info, name->str,
|
||||||
name->length).length() == name->length);
|
name->length).length() == name->length);
|
||||||
@ -4640,6 +4640,5 @@ Item* handle_sql2003_note184_exception(THD *thd, Item* left, bool equal,
|
|||||||
void sp_create_assignment_lex(THD *thd, bool no_lookahead);
|
void sp_create_assignment_lex(THD *thd, bool no_lookahead);
|
||||||
bool sp_create_assignment_instr(THD *thd, bool no_lookahead);
|
bool sp_create_assignment_instr(THD *thd, bool no_lookahead);
|
||||||
|
|
||||||
Virtual_column_info *make_json_valid_expr(THD *thd, LEX_CSTRING *field_name);
|
|
||||||
#endif /* MYSQL_SERVER */
|
#endif /* MYSQL_SERVER */
|
||||||
#endif /* SQL_LEX_INCLUDED */
|
#endif /* SQL_LEX_INCLUDED */
|
||||||
|
@ -66,7 +66,6 @@ Type_handler_tiny_blob type_handler_tiny_blob;
|
|||||||
Type_handler_medium_blob type_handler_medium_blob;
|
Type_handler_medium_blob type_handler_medium_blob;
|
||||||
Type_handler_long_blob type_handler_long_blob;
|
Type_handler_long_blob type_handler_long_blob;
|
||||||
Type_handler_blob type_handler_blob;
|
Type_handler_blob type_handler_blob;
|
||||||
Type_handler_json type_handler_json;
|
|
||||||
static Type_handler_blob_compressed type_handler_blob_compressed;
|
static Type_handler_blob_compressed type_handler_blob_compressed;
|
||||||
|
|
||||||
Type_handler_interval_DDhhmmssff type_handler_interval_DDhhmmssff;
|
Type_handler_interval_DDhhmmssff type_handler_interval_DDhhmmssff;
|
||||||
@ -2328,6 +2327,17 @@ Field *Type_handler_set::make_conversion_table_field(TABLE *table,
|
|||||||
((const Field_enum*) target)->typelib, target->charset());
|
((const Field_enum*) target)->typelib, target->charset());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*************************************************************************/
|
||||||
|
|
||||||
|
bool Type_handler::
|
||||||
|
Column_definition_validate_check_constraint(THD *thd,
|
||||||
|
Column_definition * c) const
|
||||||
|
{
|
||||||
|
return c->validate_check_constraint(thd);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
bool Type_handler_null::
|
bool Type_handler_null::
|
||||||
Column_definition_fix_attributes(Column_definition *def) const
|
Column_definition_fix_attributes(Column_definition *def) const
|
||||||
|
@ -78,6 +78,7 @@ struct Schema_specification_st;
|
|||||||
struct TABLE;
|
struct TABLE;
|
||||||
struct SORT_FIELD_ATTR;
|
struct SORT_FIELD_ATTR;
|
||||||
class Vers_history_point;
|
class Vers_history_point;
|
||||||
|
class Virtual_column_info;
|
||||||
|
|
||||||
#define my_charset_numeric my_charset_latin1
|
#define my_charset_numeric my_charset_latin1
|
||||||
|
|
||||||
@ -3280,7 +3281,6 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
virtual bool is_scalar_type() const { return true; }
|
virtual bool is_scalar_type() const { return true; }
|
||||||
virtual bool is_json_type() const { return false; }
|
|
||||||
virtual bool can_return_int() const { return true; }
|
virtual bool can_return_int() const { return true; }
|
||||||
virtual bool can_return_decimal() const { return true; }
|
virtual bool can_return_decimal() const { return true; }
|
||||||
virtual bool can_return_real() const { return true; }
|
virtual bool can_return_real() const { return true; }
|
||||||
@ -3338,6 +3338,10 @@ public:
|
|||||||
// Automatic upgrade, e.g. for ALTER TABLE t1 FORCE
|
// Automatic upgrade, e.g. for ALTER TABLE t1 FORCE
|
||||||
virtual void Column_definition_implicit_upgrade(Column_definition *c) const
|
virtual void Column_definition_implicit_upgrade(Column_definition *c) const
|
||||||
{ }
|
{ }
|
||||||
|
// Validate CHECK constraint after the parser
|
||||||
|
virtual bool Column_definition_validate_check_constraint(THD *thd,
|
||||||
|
Column_definition *c)
|
||||||
|
const;
|
||||||
// Fix attributes after the parser
|
// Fix attributes after the parser
|
||||||
virtual bool Column_definition_fix_attributes(Column_definition *c) const= 0;
|
virtual bool Column_definition_fix_attributes(Column_definition *c) const= 0;
|
||||||
/*
|
/*
|
||||||
@ -5895,14 +5899,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Type_handler_json: public Type_handler_long_blob
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~Type_handler_json() {}
|
|
||||||
virtual bool is_json_type() const { return true; }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class Type_handler_blob: public Type_handler_blob_common
|
class Type_handler_blob: public Type_handler_blob_common
|
||||||
{
|
{
|
||||||
static const Name m_name_blob;
|
static const Name m_name_blob;
|
||||||
@ -6231,7 +6227,6 @@ extern MYSQL_PLUGIN_IMPORT Type_handler_hex_hybrid type_handler_hex_hybrid;
|
|||||||
extern MYSQL_PLUGIN_IMPORT Type_handler_tiny_blob type_handler_tiny_blob;
|
extern MYSQL_PLUGIN_IMPORT Type_handler_tiny_blob type_handler_tiny_blob;
|
||||||
extern MYSQL_PLUGIN_IMPORT Type_handler_medium_blob type_handler_medium_blob;
|
extern MYSQL_PLUGIN_IMPORT Type_handler_medium_blob type_handler_medium_blob;
|
||||||
extern MYSQL_PLUGIN_IMPORT Type_handler_long_blob type_handler_long_blob;
|
extern MYSQL_PLUGIN_IMPORT Type_handler_long_blob type_handler_long_blob;
|
||||||
extern MYSQL_PLUGIN_IMPORT Type_handler_json type_handler_json;
|
|
||||||
extern MYSQL_PLUGIN_IMPORT Type_handler_blob type_handler_blob;
|
extern MYSQL_PLUGIN_IMPORT Type_handler_blob type_handler_blob;
|
||||||
|
|
||||||
extern MYSQL_PLUGIN_IMPORT Type_handler_bool type_handler_bool;
|
extern MYSQL_PLUGIN_IMPORT Type_handler_bool type_handler_bool;
|
||||||
|
55
sql/sql_type_json.cc
Normal file
55
sql/sql_type_json.cc
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019, MariaDB
|
||||||
|
|
||||||
|
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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sql_type_json.h"
|
||||||
|
#include "sql_class.h"
|
||||||
|
|
||||||
|
|
||||||
|
Type_handler_json_longtext type_handler_json_longtext;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Create JSON_VALID(field_name) expression
|
||||||
|
*/
|
||||||
|
|
||||||
|
Virtual_column_info *
|
||||||
|
Type_handler_json_longtext::make_json_valid_expr(THD *thd,
|
||||||
|
const LEX_CSTRING *field_name)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
Lex_ident_sys_st str;
|
||||||
|
Item *field, *expr;
|
||||||
|
str.set_valid_utf8(field_name);
|
||||||
|
if (unlikely(!(field= thd->lex->create_item_ident_field(thd, NullS, NullS,
|
||||||
|
&str))))
|
||||||
|
return 0;
|
||||||
|
if (unlikely(!(expr= new (thd->mem_root) Item_func_json_valid(thd, field))))
|
||||||
|
return 0;
|
||||||
|
return add_virtual_expression(thd, expr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Type_handler_json_longtext::
|
||||||
|
Column_definition_validate_check_constraint(THD *thd,
|
||||||
|
Column_definition * c) const
|
||||||
|
{
|
||||||
|
if (!c->check_constraint &&
|
||||||
|
!(c->check_constraint= make_json_valid_expr(thd, &c->field_name)))
|
||||||
|
return true;
|
||||||
|
return Type_handler::Column_definition_validate_check_constraint(thd, c);
|
||||||
|
}
|
38
sql/sql_type_json.h
Normal file
38
sql/sql_type_json.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#ifndef SQL_TYPE_JSON_INCLUDED
|
||||||
|
#define SQL_TYPE_JSON_INCLUDED
|
||||||
|
/*
|
||||||
|
Copyright (c) 2019, MariaDB
|
||||||
|
|
||||||
|
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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mariadb.h"
|
||||||
|
#include "sql_type.h"
|
||||||
|
|
||||||
|
class Type_handler_json_longtext: public Type_handler_long_blob
|
||||||
|
{
|
||||||
|
Virtual_column_info *make_json_valid_expr(THD *thd,
|
||||||
|
const LEX_CSTRING *field_name)
|
||||||
|
const;
|
||||||
|
public:
|
||||||
|
virtual ~Type_handler_json_longtext() {}
|
||||||
|
bool Column_definition_validate_check_constraint(THD *thd,
|
||||||
|
Column_definition *c) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern MYSQL_PLUGIN_IMPORT
|
||||||
|
Type_handler_json_longtext type_handler_json_longtext;
|
||||||
|
|
||||||
|
#endif // SQL_TYPE_JSON_INCLUDED
|
@ -68,6 +68,7 @@
|
|||||||
#include "sql_lex.h"
|
#include "sql_lex.h"
|
||||||
#include "sql_sequence.h"
|
#include "sql_sequence.h"
|
||||||
#include "my_base.h"
|
#include "my_base.h"
|
||||||
|
#include "sql_type_json.h"
|
||||||
|
|
||||||
/* this is to get the bison compilation windows warnings out */
|
/* this is to get the bison compilation windows warnings out */
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
@ -6689,10 +6690,6 @@ field_spec:
|
|||||||
$$= $<create_field>2;
|
$$= $<create_field>2;
|
||||||
|
|
||||||
$$->check_constraint= $4;
|
$$->check_constraint= $4;
|
||||||
if (!$4 && lex->last_field->type_handler()->is_json_type() &&
|
|
||||||
!($$->check_constraint= make_json_valid_expr(thd,
|
|
||||||
&$$->field_name)))
|
|
||||||
MYSQL_YYABORT;
|
|
||||||
|
|
||||||
if (unlikely($$->check(thd)))
|
if (unlikely($$->check(thd)))
|
||||||
MYSQL_YYABORT;
|
MYSQL_YYABORT;
|
||||||
@ -7086,7 +7083,7 @@ field_type_lob:
|
|||||||
| JSON_SYM
|
| JSON_SYM
|
||||||
{
|
{
|
||||||
Lex->charset= &my_charset_utf8mb4_bin;
|
Lex->charset= &my_charset_utf8mb4_bin;
|
||||||
$$.set(&type_handler_json);
|
$$.set(&type_handler_json_longtext);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@
|
|||||||
#include "sql_lex.h"
|
#include "sql_lex.h"
|
||||||
#include "sql_sequence.h"
|
#include "sql_sequence.h"
|
||||||
#include "my_base.h"
|
#include "my_base.h"
|
||||||
|
#include "sql_type_json.h"
|
||||||
|
|
||||||
/* this is to get the bison compilation windows warnings out */
|
/* this is to get the bison compilation windows warnings out */
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
@ -6627,10 +6628,6 @@ field_spec:
|
|||||||
$$= $<create_field>2;
|
$$= $<create_field>2;
|
||||||
|
|
||||||
$$->check_constraint= $4;
|
$$->check_constraint= $4;
|
||||||
if (!$4 && lex->last_field->type_handler()->is_json_type() &&
|
|
||||||
!($$->check_constraint= make_json_valid_expr(thd,
|
|
||||||
&$$->field_name)))
|
|
||||||
MYSQL_YYABORT;
|
|
||||||
|
|
||||||
if (unlikely($$->check(thd)))
|
if (unlikely($$->check(thd)))
|
||||||
MYSQL_YYABORT;
|
MYSQL_YYABORT;
|
||||||
@ -7076,7 +7073,7 @@ field_type_lob:
|
|||||||
| JSON_SYM
|
| JSON_SYM
|
||||||
{
|
{
|
||||||
Lex->charset= &my_charset_utf8mb4_bin;
|
Lex->charset= &my_charset_utf8mb4_bin;
|
||||||
$$.set(&type_handler_json);
|
$$.set(&type_handler_json_longtext);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 136767ae044eac53e7f3d76909d176cde0dc27a8
|
Subproject commit af8383daf03bee80b8e54ce207fa9ef1f9d83f94
|
Loading…
x
Reference in New Issue
Block a user