java - navicat中如何查看执行一条SQL语句的耗时
高洛峰
高洛峰 2017-04-18 09:50:29
0
5
802

在软件Navicat中,如何查看执行一条SQL语句的耗时。
如select * from table_name where id = '1' 如何查看当前的语句耗时。

==============================================================
通过测试发下:

SELECT * FROM idc_logistics_assign_rules WHERE id = '100'; SELECT * FROM idc_logistics_assign_rules WHERE id = '200'; //时间: 0.035s SELECT * FROM idc_logistics_assign_rules WHERE id IN ('100','200') //时间: 0.020s

我的id是主键,肯定会走索引的,那么走索引的查询应该更快啊。使用IN关键字是不走索引的,但是为什么查询要比两次主键id查询块呢?求解释。

高洛峰
高洛峰

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

reply all (5)
巴扎黑

Your in here is indexed. After executingexplain SELECT * FROM idc_logistics_assign_rules WHERE id IN ('100','200')you will see the index usage, which is useful for the index. To get the correct query time, add SQL_NO_CACHE

SELECT SQL_NO_CACHE * FROM idc_logistics_assign_rules WHERE id IN ('100','200')

注意: Do you need to use index in? It depends on the situation. That is, it depends on whether the index can be used. When the range of in is the clustered index in(1,2), it will be automatically optimized by MSSQL to id=1 or id=2. You can use explain to see it. The row it returns is 2 in(1,2) and id=1. or id=2 explain returns the same data. I can tell you responsibly that it is a useful index. Most of the mentions on the Internet about not using indexes are old materials, which have been optimized since MSSQL2K.

    伊谢尔伦

    My navicat is in the bottom row

      刘奇

      It’s almost like到处都是

        伊谢尔伦

        Your id must be of type int. Why do we need to add single quotes when querying

          PHPzhong

          There is query time in the lower right corner in seconds

            Latest Downloads
            More>
            Web Effects
            Website Source Code
            Website Materials
            Front End Template
            About us Disclaimer Sitemap
            php.cn:Public welfare online PHP training,Help PHP learners grow quickly!