mysql查询太长
我对这个 mysql 查询有问题。它需要 vmore 作为 1 天来执行...
查询是:
INSERT INTO traduction
(traduction.`id`,traduction.`traduction`,traduction.`language`,traduction.`type`)
(
SELECT cities.id,cities.name, '', 'city' FROM cities
WHERE cities.id NOT IN
(
SELECT traduction.`id` FROM traduction WHERE traduction.type='city' GROUP BY id
)
);
我对 2 个选择进行了扩展解释,它说“依赖子查询”,因此第二个选择会为城市上的每个选择播放,但我认为它没有用。
mysql 或其他 sql 服务器中有一种方法可以允许这样做吗?
或者也许是一个完整的其他查询。
这个想法是,如果一个城市没有翻译,则应该将城市名称写在翻译表中。然后我只需要查看翻译表而不是城市表。
i have a problem with this mysql query. It take vmore as 1 day to execute ...
The query is :
INSERT INTO traduction
(traduction.`id`,traduction.`traduction`,traduction.`language`,traduction.`type`)
(
SELECT cities.id,cities.name, '', 'city' FROM cities
WHERE cities.id NOT IN
(
SELECT traduction.`id` FROM traduction WHERE traduction.type='city' GROUP BY id
)
);
I made a explain extended on the 2 select and it says DEPENDENT SUBQUERY so the second select is played for every select on cities but I think it's useless.
There is a way in mysql or another sql server which can allow that ?
Or maybe a complet other query.
The idea is, if a city doesn't have a traduction, the city name should be writen in the traduction table. Then I just have to look in traduction table and not city table.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试这样的方法
还要确保表上有正确的索引,例如traduction.type或traduction.id和city.id
编辑:不存在
You can try something like this
Also ensure that you have the correct indexes on your tables, for lets say traduction.type or traduction.id and cities.id
EDIT: NOT EXISTS
您正在修改推导表,这就是内部子查询的结果无法重用的原因
You are modifying traduction table, that's why the results of inner subquery cannot be reused