V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
kn007
V2EX  ›  MySQL

请教下, MySQL 有没有办法仅记录出使用 temporary 或 filesort 的查询么?

  •  
  •   kn007 ·
    kn007 · 2015-07-09 09:48:33 +08:00 · 2162 次点击
    这是一个创建于 3186 天前的主题,其中的信息可能已经有所发展或是发生改变。

    朋友找我帮忙看下数据库,说想对一些查询做些优化。
    说是临时表创建比较多,但不知道是具体哪些查询出现问题。
    想问下有没有办法仅记录出使用某种方式的查询这种功能or工具,遂来请教一下。谢谢

    tuning-primer.sh:
    TEMP TABLES
    Current max_heap_table_size = 256 M
    Current tmp_table_size = 256 M
    Of 62452 temp tables, 36% were created on disk
    Perhaps you should increase your tmp_table_size and/or max_heap_table_size
    to reduce the number of disk-based temporary tables
    Note! BLOB and TEXT columns are not allow in memory tables.
    If you are using these columns raising these values might not impact your
    ratio of on disk temp tables.

    mysqltuner.pl:
    [!!] Temporary tables created on disk: 57% (35K on disk / 62K total)

    临时表存储在/dev/shm上,没有慢查询目前,就是看着上面的数据有些不爽。。。

    3 条回复    2015-07-09 16:53:29 +08:00
    kn007
        1
    kn007  
    OP
       2015-07-09 14:32:30 +08:00
    up一下
    realpg
        2
    realpg  
       2015-07-09 15:16:26 +08:00   ❤️ 1
    开发人员脑袋里对MYSQL基本的查询优化没概念

    尤其是做商业软件的JAVA程序员最好干这个,我就见过给我写一个巨变态的大查询,就为了只用一个查询实现功能,那个SQL指令目测都有1500个字节,explain起来里面filesort不计其数

    还是在程序设计查询的时候要想着数据库结构,想着怎么有效利用索引才是靠谱办法

    还有,并不是filesort和temportary table就不靠谱,要结合数据量,有些查询没必要优化,因为数据两盒内存开销肯定吃得起,创建专门索引增容反而更坑
    kn007
        3
    kn007  
    OP
       2015-07-09 16:53:29 +08:00
    @realpg 非常感谢,现在确实没有慢查询,i/o也不高。貌似也确实没什么必要。
    我其实是想了解下,有没有实现这种功能的方法或工具。

    话说1500个字节的命令,这是什么查询。。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2814 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 14:38 · PVG 22:38 · LAX 07:38 · JFK 10:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.