mysql - sql问题请教
高洛峰
高洛峰 2017-04-17 12:59:54
[MySQL讨论组]

select a.,b from count a, user b where a.aid = b.aid order by b.count desc limit 10

在count字段中排名前10的字段,找出aid相同的另外一个表的所有字段。
这句能实现,但效率太低,几万记录查询都几秒了。有简单的办法吗

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回复(1)
迷茫

如果你是是用Mysql,我觉得可以参考下这里的内容
https://dev.mysql.com/doc/refman/5.0/en/order-by-optimization.html

To increase ORDER BY speed, check whether you can get MySQL to use indexes rather than an extra sorting phase. If this is not possible, you can try the following strategies:

Increase the sort_buffer_size variable value.

Increase the read_rnd_buffer_size variable value.

Use less RAM per row by declaring columns only as large as they need to be to hold the values stored in them. For example, CHAR(16) is better than CHAR(200) if values never exceed 16 characters.

Change the tmpdir system variable to point to a dedicated file system with large amounts of free space. The variable value can list several paths that are used in round-robin fashion; you can use this feature to spread the load across several directories. Paths should be separated by colon characters (“:”) on Unix and semicolon characters (“;”) on Windows, NetWare, and OS/2. The paths should name directories in file systems located on different physical disks, not different partitions on the same disk.

除此之外,也可以试试复合索引,具体可以看看这里
http://www.cnblogs.com/anywei/archive/2011/12/12/mysql.html

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号