mysql proc の外部で実行されるまったく同じクエリが、その内部で同じデータを返さない理由がわかりません。
これがプロセスです。
DELIMITER $$
USE `poll_app`$$
DROP PROCEDURE IF EXISTS `record_new_vote`$$
CREATE DEFINER=`somemysqluser`@`%` PROCEDURE `record_new_vote`(
p_member_id INT (10),
p_option_ids VARCHAR(255), -- 12,13,14,15
p_option_id INT (10),
p_stream_id INT (10),
p_scene_id INT (10)
)
BEGIN
DECLARE _user_already_voted VARCHAR(255);
DECLARE _update_off_id INT;
DECLARE _update_on_id INT;
-- 1. Query to figure out what to update
SELECT
p_member_id, p_option_ids, p_option_id, p_stream_id, p_scene_id;
SET SESSION group_concat_max_len = 1000000;
SELECT
GROUP_CONCAT(selections.status, "~~~", selections.id, "~~~", selections.option_id),
GROUP_CONCAT(IF(selections.status = "ON", id, NULL)),
GROUP_CONCAT(IF(selections.status = "OFF" && selections.option_id = p_option_id, selections.id, NULL))
INTO
_user_already_voted, _update_off_id, _update_on_id
FROM
selections
WHERE
selections.member_id = p_member_id
AND
selections.option_id IN (p_option_ids)
AND
selections.stream_id = p_stream_id
AND
selections.scene_id = p_scene_id;
-- 2. Check to see if the user has already voted on the poll or not
IF (_user_already_voted IS NOT NULL) THEN
SELECT
_user_already_voted, _update_off_id, _update_on_id;
END IF;
END$$
DELIMITER ;
ここにそれが出力するものがあります
[ [ RowDataPacket {
p_member_id: 107,
p_option_ids: '1005,1006,1007,1008',
p_option_id: 1007,
p_stream_id: 7,
p_scene_id: 1 } ],
[ RowDataPacket {
_user_already_voted: 'OFF~~~451~~~1005',
_update_off_id: NULL,
_update_on_id: NULL } ],
proc の外部で選択クエリを実行すると (同じデータがプラグインされた状態で)
SELECT
GROUP_CONCAT(`status`, "~~~", id, "~~~", option_id) AS "selections",
GROUP_CONCAT(IF(`status` = "ON", id, NULL)) AS "id_to_turn_status_off",
GROUP_CONCAT(IF(`status` = "OFF" && option_id = 1007, id, NULL)) AS "id_to_turn_status_on"
FROM
selections
WHERE
member_id = 107
AND
option_id IN (1005,1006,1007,1008)
AND
stream_id = 7
AND
scene_id = 1
結果
selections id_to_turn_status_off id_to_turnstatus_on
OFF~~~451~~~1005,ON~~~452~~~1006 452 null
ご覧のとおり、グループ連結文字列はそれほど長くなく、id_to_turn_status_off は 452 ですが、同じクエリが proc で実行される場合、変数 _update_off_id は NULL です。
私の人生でこれを理解することはできません。どんな助けでも大歓迎です。