Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
c6e3fe29
Commit
c6e3fe29
authored
Apr 27, 2024
by
Alexander Barkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-30646 View created via JSON_ARRAYAGG returns incorrect json object
Backporting
add782a1
from 10.6, this fixes the problem.
parent
dc25d600
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
59 additions
and
12 deletions
+59
-12
mysql-test/main/func_json.result
mysql-test/main/func_json.result
+3
-3
mysql-test/suite/json/r/type_json.result
mysql-test/suite/json/r/type_json.result
+8
-0
mysql-test/suite/json/t/type_json.test
mysql-test/suite/json/t/type_json.test
+9
-0
sql/item_jsonfunc.cc
sql/item_jsonfunc.cc
+1
-1
sql/item_jsonfunc.h
sql/item_jsonfunc.h
+1
-0
sql/sql_select.cc
sql/sql_select.cc
+22
-0
sql/table.cc
sql/table.cc
+13
-8
sql/table.h
sql/table.h
+2
-0
No files found.
mysql-test/main/func_json.result
View file @
c6e3fe29
...
...
@@ -1640,9 +1640,9 @@ SELECT t1.id, JSON_ARRAYAGG(JSON_OBJECT('id',t2.id) ORDER BY t2.id) as materials
from t1 LEFT JOIN t2 on t1.id = t2.owner_id
GROUP BY t1.id ORDER BY id;
id materials
1 [
"{\"id\": 1}","{\"id\": 2}"
]
2 [
"{\"id\": 3}"
]
3 [
"{\"id\": 4}"
]
1 [
{"id": 1},{"id": 2}
]
2 [
{"id": 3}
]
3 [
{"id": 4}
]
DROP TABLE t1;
DROP TABLE t2;
#
...
...
mysql-test/suite/json/r/type_json.result
View file @
c6e3fe29
...
...
@@ -2880,5 +2880,13 @@ DROP PROCEDURE p1;
DROP PROCEDURE p2;
DROP TABLE t1, t1c, t2;
#
# MDEV-30646 View created via JSON_ARRAYAGG returns incorrect json object
#
CREATE VIEW v1 AS SELECT JSON_OBJECT('plugin','unix_socket') as v1_json;
SELECT JSON_ARRAYAGG(v1_json) FROM v1;
JSON_ARRAYAGG(v1_json)
[{"plugin": "unix_socket"}]
DROP VIEW v1;
#
# End of 10.5 tests
#
mysql-test/suite/json/t/type_json.test
View file @
c6e3fe29
...
...
@@ -138,6 +138,15 @@ DROP PROCEDURE p2;
DROP
TABLE
t1
,
t1c
,
t2
;
--
echo
#
--
echo
# MDEV-30646 View created via JSON_ARRAYAGG returns incorrect json object
--
echo
#
CREATE
VIEW
v1
AS
SELECT
JSON_OBJECT
(
'plugin'
,
'unix_socket'
)
as
v1_json
;
SELECT
JSON_ARRAYAGG
(
v1_json
)
FROM
v1
;
DROP
VIEW
v1
;
--
echo
#
--
echo
# End of 10.5 tests
--
echo
#
sql/item_jsonfunc.cc
View file @
c6e3fe29
...
...
@@ -1633,7 +1633,7 @@ longlong Item_func_json_contains_path::val_int()
`CONVERT(arg USING charset)` is actually a general purpose string
expression, not a JSON expression.
*/
static
bool
is_json_type
(
const
Item
*
item
)
bool
is_json_type
(
const
Item
*
item
)
{
for
(
;
;
)
{
...
...
sql/item_jsonfunc.h
View file @
c6e3fe29
...
...
@@ -640,5 +640,6 @@ class Item_func_json_objectagg : public Item_sum
{
return
get_item_copy
<
Item_func_json_objectagg
>
(
thd
,
this
);
}
};
extern
bool
is_json_type
(
const
Item
*
item
);
#endif
/* ITEM_JSONFUNC_INCLUDED */
sql/sql_select.cc
View file @
c6e3fe29
...
...
@@ -18569,6 +18569,25 @@ Field *Item_func_sp::create_tmp_field_ex(MEM_ROOT *root, TABLE *table,
return
result
;
}
static
bool
make_json_valid_expr
(
TABLE
*
table
,
Field
*
field
)
{
THD
*
thd
=
table
->
in_use
;
Query_arena
backup_arena
;
Item
*
expr
,
*
item_field
;
if
(
!
table
->
expr_arena
&&
table
->
init_expr_arena
(
thd
->
mem_root
))
return
1
;
thd
->
set_n_backup_active_arena
(
table
->
expr_arena
,
&
backup_arena
);
if
((
item_field
=
new
(
thd
->
mem_root
)
Item_field
(
thd
,
field
))
&&
(
expr
=
new
(
thd
->
mem_root
)
Item_func_json_valid
(
thd
,
item_field
)))
field
->
check_constraint
=
add_virtual_expression
(
thd
,
expr
);
thd
->
restore_active_arena
(
table
->
expr_arena
,
&
backup_arena
);
return
field
->
check_constraint
==
NULL
;
}
/**
Create field for temporary table.
...
...
@@ -18614,6 +18633,9 @@ Field *create_tmp_field(TABLE *table, Item *item,
make_copy_field
);
Field
*
result
=
item
->
create_tmp_field_ex
(
table
->
in_use
->
mem_root
,
table
,
&
src
,
&
prm
);
if
(
is_json_type
(
item
)
&&
make_json_valid_expr
(
table
,
result
))
result
=
NULL
;
*
from_field
=
src
.
field
();
*
default_field
=
src
.
default_field
();
if
(
src
.
item_result_field
())
...
...
sql/table.cc
View file @
c6e3fe29
...
...
@@ -53,6 +53,17 @@
#define MYSQL57_GENERATED_FIELD 128
#define MYSQL57_GCOL_HEADER_SIZE 4
bool
TABLE
::
init_expr_arena
(
MEM_ROOT
*
mem_root
)
{
/*
We need to use CONVENTIONAL_EXECUTION here to ensure that
any new items created by fix_fields() are not reverted.
*/
expr_arena
=
new
(
alloc_root
(
mem_root
,
sizeof
(
Query_arena
)))
Query_arena
(
mem_root
,
Query_arena
::
STMT_CONVENTIONAL_EXECUTION
);
return
expr_arena
==
NULL
;
}
struct
extra2_fields
{
LEX_CUSTRING
version
;
...
...
@@ -1145,14 +1156,8 @@ bool parse_vcol_defs(THD *thd, MEM_ROOT *mem_root, TABLE *table,
table
->
s
->
table_check_constraints
*
sizeof
(
Virtual_column_info
*
));
DBUG_ASSERT
(
table
->
expr_arena
==
NULL
);
/*
We need to use CONVENTIONAL_EXECUTION here to ensure that
any new items created by fix_fields() are not reverted.
*/
table
->
expr_arena
=
new
(
alloc_root
(
mem_root
,
sizeof
(
Query_arena
)))
Query_arena
(
mem_root
,
Query_arena
::
STMT_CONVENTIONAL_EXECUTION
);
if
(
!
table
->
expr_arena
)
if
(
table
->
init_expr_arena
(
mem_root
))
DBUG_RETURN
(
1
);
thd
->
set_n_backup_active_arena
(
table
->
expr_arena
,
&
backup_arena
);
...
...
sql/table.h
View file @
c6e3fe29
...
...
@@ -1645,6 +1645,8 @@ struct TABLE
m_needs_reopen
=
value
;
}
bool
init_expr_arena
(
MEM_ROOT
*
mem_root
);
bool
alloc_keys
(
uint
key_count
);
bool
check_tmp_key
(
uint
key
,
uint
key_parts
,
uint
(
*
next_field_no
)
(
uchar
*
),
uchar
*
arg
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment