Skip to content

Commit 28f18aa

Browse files
committed
Merge branch '10.4' into bb-10.4-mdev16188
2 parents a44f2c3 + 62c0ac2 commit 28f18aa

File tree

13 files changed

+127
-46
lines changed

13 files changed

+127
-46
lines changed

libmysqld/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
110110
../sql/sql_analyze_stmt.cc ../sql/sql_analyze_stmt.h
111111
../sql/compat56.cc
112112
../sql/sql_type.cc ../sql/sql_type.h
113+
../sql/sql_type_json.cc
113114
../sql/table_cache.cc ../sql/mf_iocache_encr.cc
114115
../sql/item_inetfunc.cc
115116
../sql/wsrep_dummy.cc ../sql/encryption.cc

sql/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ SET (SQL_SOURCE
132132
rpl_gtid.cc rpl_parallel.cc
133133
semisync.cc semisync_master.cc semisync_slave.cc
134134
semisync_master_ack_receiver.cc
135-
sql_type.cc
135+
sql_type.cc sql_type_json.cc
136136
item_windowfunc.cc sql_window.cc
137137
sql_cte.cc
138138
item_vers.cc

sql/field.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10501,6 +10501,13 @@ bool Column_definition::fix_attributes_temporal_with_time(uint int_part_length)
1050110501
}
1050210502

1050310503

10504+
bool Column_definition::validate_check_constraint(THD *thd)
10505+
{
10506+
return check_constraint &&
10507+
check_expression(check_constraint, &field_name, VCOL_CHECK_FIELD);
10508+
}
10509+
10510+
1050410511
bool Column_definition::check(THD *thd)
1050510512
{
1050610513
DBUG_ENTER("Column_definition::check");
@@ -10515,9 +10522,8 @@ bool Column_definition::check(THD *thd)
1051510522
DBUG_RETURN(TRUE);
1051610523
}
1051710524

10518-
if (check_constraint &&
10519-
check_expression(check_constraint, &field_name, VCOL_CHECK_FIELD))
10520-
DBUG_RETURN(1);
10525+
if (type_handler()->Column_definition_validate_check_constraint(thd, this))
10526+
DBUG_RETURN(TRUE);
1052110527

1052210528
if (default_value)
1052310529
{

sql/field.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4675,6 +4675,7 @@ class Column_definition: public Sql_alloc,
46754675
bool fix_attributes_bit();
46764676

46774677
bool check(THD *thd);
4678+
bool validate_check_constraint(THD *thd);
46784679

46794680
bool stored_in_db() const { return !vcol_info || vcol_info->stored_in_db; }
46804681

sql/sql_lex.cc

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9587,21 +9587,3 @@ bool LEX::sp_proc_stmt_statement_finalize(THD *thd, bool no_lookahead)
95879587
lip->get_tok_start());
95889588
return LEX::sp_proc_stmt_statement_finalize_buf(thd, qbuf);
95899589
}
9590-
9591-
9592-
/**
9593-
Create JSON_VALID(field_name) expression
9594-
*/
9595-
9596-
Virtual_column_info *make_json_valid_expr(THD *thd, LEX_CSTRING *field_name)
9597-
{
9598-
Lex_ident_sys_st str;
9599-
Item *field, *expr;
9600-
str.set_valid_utf8(field_name);
9601-
if (unlikely(!(field= thd->lex->create_item_ident_field(thd, NullS, NullS,
9602-
&str))))
9603-
return 0;
9604-
if (unlikely(!(expr= new (thd->mem_root) Item_func_json_valid(thd, field))))
9605-
return 0;
9606-
return add_virtual_expression(thd, expr);
9607-
}

sql/sql_lex.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ struct Lex_ident_sys_st: public LEX_CSTRING
148148
bool copy_or_convert(THD *thd, const Lex_ident_cli_st *str, CHARSET_INFO *cs);
149149
bool is_null() const { return str == NULL; }
150150
bool to_size_number(ulonglong *to) const;
151-
void set_valid_utf8(LEX_CSTRING *name)
151+
void set_valid_utf8(const LEX_CSTRING *name)
152152
{
153153
DBUG_ASSERT(Well_formed_prefix(system_charset_info, name->str,
154154
name->length).length() == name->length);
@@ -4640,6 +4640,5 @@ Item* handle_sql2003_note184_exception(THD *thd, Item* left, bool equal,
46404640
void sp_create_assignment_lex(THD *thd, bool no_lookahead);
46414641
bool sp_create_assignment_instr(THD *thd, bool no_lookahead);
46424642

4643-
Virtual_column_info *make_json_valid_expr(THD *thd, LEX_CSTRING *field_name);
46444643
#endif /* MYSQL_SERVER */
46454644
#endif /* SQL_LEX_INCLUDED */

sql/sql_type.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ Type_handler_tiny_blob type_handler_tiny_blob;
6666
Type_handler_medium_blob type_handler_medium_blob;
6767
Type_handler_long_blob type_handler_long_blob;
6868
Type_handler_blob type_handler_blob;
69-
Type_handler_json type_handler_json;
7069
static Type_handler_blob_compressed type_handler_blob_compressed;
7170

7271
Type_handler_interval_DDhhmmssff type_handler_interval_DDhhmmssff;
@@ -2328,6 +2327,17 @@ Field *Type_handler_set::make_conversion_table_field(TABLE *table,
23282327
((const Field_enum*) target)->typelib, target->charset());
23292328
}
23302329

2330+
2331+
/*************************************************************************/
2332+
2333+
bool Type_handler::
2334+
Column_definition_validate_check_constraint(THD *thd,
2335+
Column_definition * c) const
2336+
{
2337+
return c->validate_check_constraint(thd);
2338+
}
2339+
2340+
23312341
/*************************************************************************/
23322342
bool Type_handler_null::
23332343
Column_definition_fix_attributes(Column_definition *def) const

sql/sql_type.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct Schema_specification_st;
7878
struct TABLE;
7979
struct SORT_FIELD_ATTR;
8080
class Vers_history_point;
81+
class Virtual_column_info;
8182

8283
#define my_charset_numeric my_charset_latin1
8384

@@ -3280,7 +3281,6 @@ class Type_handler
32803281
return true;
32813282
}
32823283
virtual bool is_scalar_type() const { return true; }
3283-
virtual bool is_json_type() const { return false; }
32843284
virtual bool can_return_int() const { return true; }
32853285
virtual bool can_return_decimal() const { return true; }
32863286
virtual bool can_return_real() const { return true; }
@@ -3338,6 +3338,10 @@ class Type_handler
33383338
// Automatic upgrade, e.g. for ALTER TABLE t1 FORCE
33393339
virtual void Column_definition_implicit_upgrade(Column_definition *c) const
33403340
{ }
3341+
// Validate CHECK constraint after the parser
3342+
virtual bool Column_definition_validate_check_constraint(THD *thd,
3343+
Column_definition *c)
3344+
const;
33413345
// Fix attributes after the parser
33423346
virtual bool Column_definition_fix_attributes(Column_definition *c) const= 0;
33433347
/*
@@ -5895,14 +5899,6 @@ class Type_handler_long_blob: public Type_handler_blob_common
58955899
};
58965900

58975901

5898-
class Type_handler_json: public Type_handler_long_blob
5899-
{
5900-
public:
5901-
virtual ~Type_handler_json() {}
5902-
virtual bool is_json_type() const { return true; }
5903-
};
5904-
5905-
59065902
class Type_handler_blob: public Type_handler_blob_common
59075903
{
59085904
static const Name m_name_blob;
@@ -6231,7 +6227,6 @@ extern MYSQL_PLUGIN_IMPORT Type_handler_hex_hybrid type_handler_hex_hybrid;
62316227
extern MYSQL_PLUGIN_IMPORT Type_handler_tiny_blob type_handler_tiny_blob;
62326228
extern MYSQL_PLUGIN_IMPORT Type_handler_medium_blob type_handler_medium_blob;
62336229
extern MYSQL_PLUGIN_IMPORT Type_handler_long_blob type_handler_long_blob;
6234-
extern MYSQL_PLUGIN_IMPORT Type_handler_json type_handler_json;
62356230
extern MYSQL_PLUGIN_IMPORT Type_handler_blob type_handler_blob;
62366231

62376232
extern MYSQL_PLUGIN_IMPORT Type_handler_bool type_handler_bool;

sql/sql_type_json.cc

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright (c) 2019, MariaDB
3+
4+
This program is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU General Public License
6+
as published by the Free Software Foundation; version 2 of
7+
the License.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#include "sql_type_json.h"
20+
#include "sql_class.h"
21+
22+
23+
Type_handler_json_longtext type_handler_json_longtext;
24+
25+
26+
/**
27+
Create JSON_VALID(field_name) expression
28+
*/
29+
30+
Virtual_column_info *
31+
Type_handler_json_longtext::make_json_valid_expr(THD *thd,
32+
const LEX_CSTRING *field_name)
33+
const
34+
{
35+
Lex_ident_sys_st str;
36+
Item *field, *expr;
37+
str.set_valid_utf8(field_name);
38+
if (unlikely(!(field= thd->lex->create_item_ident_field(thd, NullS, NullS,
39+
&str))))
40+
return 0;
41+
if (unlikely(!(expr= new (thd->mem_root) Item_func_json_valid(thd, field))))
42+
return 0;
43+
return add_virtual_expression(thd, expr);
44+
}
45+
46+
47+
bool Type_handler_json_longtext::
48+
Column_definition_validate_check_constraint(THD *thd,
49+
Column_definition * c) const
50+
{
51+
if (!c->check_constraint &&
52+
!(c->check_constraint= make_json_valid_expr(thd, &c->field_name)))
53+
return true;
54+
return Type_handler::Column_definition_validate_check_constraint(thd, c);
55+
}

sql/sql_type_json.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef SQL_TYPE_JSON_INCLUDED
2+
#define SQL_TYPE_JSON_INCLUDED
3+
/*
4+
Copyright (c) 2019, MariaDB
5+
6+
This program is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU General Public License
8+
as published by the Free Software Foundation; version 2 of
9+
the License.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program; if not, write to the Free Software
18+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*/
20+
21+
#include "mariadb.h"
22+
#include "sql_type.h"
23+
24+
class Type_handler_json_longtext: public Type_handler_long_blob
25+
{
26+
Virtual_column_info *make_json_valid_expr(THD *thd,
27+
const LEX_CSTRING *field_name)
28+
const;
29+
public:
30+
virtual ~Type_handler_json_longtext() {}
31+
bool Column_definition_validate_check_constraint(THD *thd,
32+
Column_definition *c) const;
33+
};
34+
35+
extern MYSQL_PLUGIN_IMPORT
36+
Type_handler_json_longtext type_handler_json_longtext;
37+
38+
#endif // SQL_TYPE_JSON_INCLUDED

0 commit comments

Comments
 (0)