数据库
首页 > 数据库> > MySQL查询加速

MySQL查询加速

作者:互联网

我的查询速度有问题-目前它的运行时间约为16秒,我需要加快速度!

我的表方案如下:

使用者:

> id(int 10,主键)
>用户名(varchar 100)
>密码(varchar 100)

Users_meta:

> id(int 10,主键)
>用户(int 10)
>元(varchar 100)
>值(长文本)

我需要从用户元表的各个行(例如名字,姓氏等)中返回数据作为列.这个查询可以完成任务,但是运行太慢:

SELECT
Users.id as id,
Users.username as username,
firstName.value as metaFirstName,
lastName.value as metaLastName,
userLevel.value as metaUsername,
employer.value as metaEmployer,
gto.value as metaGTO
FROM Users
LEFT JOIN (Users_meta as firstName) ON (firstName.user = Users.id AND firstName.meta = 'first_name')
LEFT JOIN (Users_meta as lastName) ON (lastName.user = Users.id AND lastName.meta = 'last_name')
LEFT JOIN (Users_meta as userLevel) ON (userLevel.user = Users.id AND userLevel.meta = 'user_level')
LEFT JOIN (Users_meta as employer) ON (employer.user = Users.id AND employer.meta = 'employer')
LEFT JOIN (Users_meta as gto) ON (gto.user = Users.id AND gto.meta = 'gto')

我还需要能够将WHERE和ORDER BY子句添加到查询中.

谢谢你的帮助.

标签:performance,left-join,mysql,database
来源: https://codeday.me/bug/20191201/2080373.html