2
我已经设法写下面的查询,这很好。我的问题是我使用了很多次,我认为它保证它自己的观点,但是当我有phpmyadmin为我创建视图时,以前需要0.0060秒的查询现在需要6.2094秒。有没有办法重写这个查询作为SQL视图工作
我的查询:
SELECT tr.uuid, tr.creator,
(
SELECT
GROUP_CONCAT(name)
FROM tags as t1
WHERE t1.uuid = tr.uuid and t1.type = "name"
GROUP BY t1.uuid
) as names,
(
SELECT GROUP_CONCAT(name)
FROM tags as t2
WHERE t2.uuid = tr.uuid and t2.type = "tag"
GROUP BY t2.uuid
) as tags
FROM `tags` as tr
phpMyAdmin的的转换:
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `textagname` AS
select
`tr`.`uuid` AS `uuid`,
`tr`.`creator` AS `creator`,
(
select group_concat(`t1`.`name` separator ',') AS `GROUP_CONCAT(name)`
from `tags` `t1`
where ((`t1`.`uuid` = `tr`.`uuid`) and (`t1`.`type` = 'name'))
group by `t1`.`uuid`
) AS `names`,
(
select group_concat(`t2`.`name` separator ',') AS `GROUP_CONCAT(name)`
from `tags` `t2`
where ((`t2`.`uuid` = `tr`.`uuid`) and (`t2`.`type` = 'tag'))
group by `t2`.`uuid`
) AS `tags`
from `tags` `tr`
任何想法,我怎样才能使我的观点更多的时间效率?
PS:这里是tags
表结构:
Column Type Null Default Comments
------- ----------- ---- ------- ------------------
uuid varchar(36) No key of texture
name varchar(64) No tag name
creator varchar(36) Yes NULL creator of the tag
type varchar(36) No name, or tag
什么是'名称'子查询应该做的?你似乎没有使用它(除了乘以结果的数量)。 – eggyal
我试图做的查询是生成一个表格,每个纹理的UUID与纹理的名称和它的标签的CSV列表。 – TechplexEngineer