MySQL GROUP_CONCAT 砍掉一半数据(有时)
MySQL GROUP_CONCAT chopping off half the data (sometimes)
我似乎遇到了一个非常奇怪的问题...以下查询截断了 GROUP_CONCAT
的一些结果
select
booking_id,
group_concat(booking_resource_info_grouped_bla)
from (
SELECT
b.id AS booking_id,
GROUP_CONCAT(DISTINCT booking_resource_info SEPARATOR '{{hr}}') AS `booking_resource_info_grouped_bla`
FROM
(
SELECT 492185 AS id, '25ft Climbing 1' as booking_resource_info
UNION ALL
SELECT 492185 AS id, '25ft Climbing 2' as booking_resource_info
UNION ALL
SELECT 492185 AS id, '3 G Swing' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Archery 1' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Body Boarding' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Canadian Canoes' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Catering 1' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Crate Stack 1' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Kayak 1' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Kayak 2' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Orange Lodge' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Lake' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Low Ropes' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Marquee 1 - Site 3' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Parker Lodge' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Raft Building 1' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Raft Building 2' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Raft Building 3' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'School Package 1' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Apple Lodge' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Team Building 1' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Tomahawks' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Banana Lodge' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Wobble Pole' as booking_resource_info
) b
GROUP BY b.id
UNION ALL
SELECT
123 AS booking_id,
'' AS `booking_resource_info_grouped_bla`
) test
GROUP BY booking_id
;
这会产生:
25ft Climbing 1{{hr}}25ft Climbing 2{{hr}}3 G Swing{{hr}}Apple
Lodge{{hr}}Archery 1{{hr}}Banana Lodge{{hr}}Body
Boarding{{hr}}Canadian Canoes{{hr}}Catering 1{{hr}}Crate Stack
1{{hr}}Kayak 1{{hr}}Kayak 2{{hr}}Kiwi Lodge{{hr}}Lake{{hr}}Low
Ropes{{hr}}Marquee 1 - Site 3{{hr}}Orange Lodge{{hr}}Raft Building
1{{hr}}Raft Building 2{{hr}}Raft Bui
如您所见,尾部Raft Bui
不完整。
另一方面,我已经让这个查询正常工作了。我让它在另一台服务器上工作,所以我重新启动了其中一个,然后那个也开始工作了。
我在 MySQL 5.6 和 5.7 上都进行了广泛的尝试——这两个版本都产生了预期和非预期的结果。
我在 db-fiddle.com 上尝试了 MySQL 8.0,这是唯一产生预期结果的版本。
是否有我遗漏的设置/内存限制/已知问题?
值得注意的是,当查询的 UNION ALL
部分被删除时,此查询 总是 有效,因此虚拟联合都在那里,因此问题是可重现的.
SET SESSION group_concat_max_len = 1000000;
这将解决您的问题。
默认组连接的最大长度为 1024
更多信息:https://www.namasteui.com/mysql-group_concat-maximum-length/
我似乎遇到了一个非常奇怪的问题...以下查询截断了 GROUP_CONCAT
select
booking_id,
group_concat(booking_resource_info_grouped_bla)
from (
SELECT
b.id AS booking_id,
GROUP_CONCAT(DISTINCT booking_resource_info SEPARATOR '{{hr}}') AS `booking_resource_info_grouped_bla`
FROM
(
SELECT 492185 AS id, '25ft Climbing 1' as booking_resource_info
UNION ALL
SELECT 492185 AS id, '25ft Climbing 2' as booking_resource_info
UNION ALL
SELECT 492185 AS id, '3 G Swing' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Archery 1' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Body Boarding' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Canadian Canoes' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Catering 1' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Crate Stack 1' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Kayak 1' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Kayak 2' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Orange Lodge' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Lake' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Low Ropes' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Marquee 1 - Site 3' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Parker Lodge' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Raft Building 1' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Raft Building 2' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Raft Building 3' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'School Package 1' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Apple Lodge' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Team Building 1' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Tomahawks' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Banana Lodge' as booking_resource_info
UNION ALL
SELECT 492185 AS id, 'Wobble Pole' as booking_resource_info
) b
GROUP BY b.id
UNION ALL
SELECT
123 AS booking_id,
'' AS `booking_resource_info_grouped_bla`
) test
GROUP BY booking_id
;
这会产生:
25ft Climbing 1{{hr}}25ft Climbing 2{{hr}}3 G Swing{{hr}}Apple Lodge{{hr}}Archery 1{{hr}}Banana Lodge{{hr}}Body Boarding{{hr}}Canadian Canoes{{hr}}Catering 1{{hr}}Crate Stack 1{{hr}}Kayak 1{{hr}}Kayak 2{{hr}}Kiwi Lodge{{hr}}Lake{{hr}}Low Ropes{{hr}}Marquee 1 - Site 3{{hr}}Orange Lodge{{hr}}Raft Building 1{{hr}}Raft Building 2{{hr}}Raft Bui
如您所见,尾部Raft Bui
不完整。
另一方面,我已经让这个查询正常工作了。我让它在另一台服务器上工作,所以我重新启动了其中一个,然后那个也开始工作了。
我在 MySQL 5.6 和 5.7 上都进行了广泛的尝试——这两个版本都产生了预期和非预期的结果。 我在 db-fiddle.com 上尝试了 MySQL 8.0,这是唯一产生预期结果的版本。
是否有我遗漏的设置/内存限制/已知问题?
值得注意的是,当查询的 UNION ALL
部分被删除时,此查询 总是 有效,因此虚拟联合都在那里,因此问题是可重现的.
SET SESSION group_concat_max_len = 1000000;
这将解决您的问题。 默认组连接的最大长度为 1024
更多信息:https://www.namasteui.com/mysql-group_concat-maximum-length/