mysql 中的触发器插入多行而不是一行
trigger in mysql inserts multiple rows instead of one
我正在尝试在单独的 table(名为 bugs
)触发器中插入来自 4 个不同 table 的 4 列的总和,如下所示:
SELECT
uat_reopened_stats.release_name,
(uat_reopened_stats.rate_bugs + qa_reopened_stats.rate_bugs + closed_reopened_stats.rate_bugs + done_reopened_stats.rate_bugs)
INTO @releasename, @bugstotalreopenrate
FROM qa_reopened_stats
JOIN uat_reopened_stats
ON qa_reopened_stats.release_name = uat_reopened_stats.release_name
JOIN closed_reopened_stats
ON closed_reopened_stats.release_name = uat_reopened_stats.release_name
JOIN done_reopened_stats
ON done_reopened_stats.release_name = uat_reopened_stats.release_name;
INSERT INTO release_stats (release_name, bugs_total_reopen_rate)
VALUES (@releasename, @bugstotalreopenrate)
ON DUPLICATE KEY UPDATE
release_name=@releasename,
bugs_total_reopen_rate=@bugstotalreopenrate;
END
然而,当触发器被执行时(并且release_stats
table 预先为空,我最终得到了 11(!)行!
MySQL [jira_statistics]> select * from release_stats;
+--------------+------------------------+
| release_name | bugs_total_reopen_rate |
+--------------+------------------------+
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
+--------------+------------------------+
为什么会这样?
出于某种原因,将 release_name
设置为 table release_stats
上的主键后问题消失了。
我正在尝试在单独的 table(名为 bugs
)触发器中插入来自 4 个不同 table 的 4 列的总和,如下所示:
SELECT
uat_reopened_stats.release_name,
(uat_reopened_stats.rate_bugs + qa_reopened_stats.rate_bugs + closed_reopened_stats.rate_bugs + done_reopened_stats.rate_bugs)
INTO @releasename, @bugstotalreopenrate
FROM qa_reopened_stats
JOIN uat_reopened_stats
ON qa_reopened_stats.release_name = uat_reopened_stats.release_name
JOIN closed_reopened_stats
ON closed_reopened_stats.release_name = uat_reopened_stats.release_name
JOIN done_reopened_stats
ON done_reopened_stats.release_name = uat_reopened_stats.release_name;
INSERT INTO release_stats (release_name, bugs_total_reopen_rate)
VALUES (@releasename, @bugstotalreopenrate)
ON DUPLICATE KEY UPDATE
release_name=@releasename,
bugs_total_reopen_rate=@bugstotalreopenrate;
END
然而,当触发器被执行时(并且release_stats
table 预先为空,我最终得到了 11(!)行!
MySQL [jira_statistics]> select * from release_stats;
+--------------+------------------------+
| release_name | bugs_total_reopen_rate |
+--------------+------------------------+
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
+--------------+------------------------+
为什么会这样?
出于某种原因,将 release_name
设置为 table release_stats
上的主键后问题消失了。