zoukankan      html  css  js  c++  java
  • 同样的sql语句,数据不一样导致有些命中索引、有些没有

    表结构

    CREATE TABLE `llt_orders` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `uuid` char(36) COLLATE utf8mb4_unicode_ci NOT NULL,
    `status` tinyint(3) unsigned NOT NULL DEFAULT '0',
    `type` tinyint(3) unsigned NOT NULL,
    `order_id` int(10) unsigned DEFAULT NULL,
    `order_number` bigint(20) DEFAULT NULL,
    `pharmacy_id` int(10) unsigned DEFAULT NULL,
    `user_id` int(10) unsigned NOT NULL,
    `subtotal` decimal(10,2) NOT NULL,
    `vendor_id` int(10) unsigned DEFAULT 0,
    `note` text COLLATE utf8mb4_unicode_ci NOT NULL,
    `count_status` int(10) unsigned DEFAULT NULL,
    `created_at` timestamp NULL DEFAULT NULL,
    `updated_at` timestamp NULL DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `orders_order_number_unique` (`order_number`),
    KEY `orders_user_id_foreign` (`user_id`),
    KEY `orders_order_id_foreign` (`order_id`),
    KEY `orders_pharmacy_id_foreign` (`pharmacy_id`),
    KEY `vendor_id` (`vendor_id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=6091 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

    没命中索引
    EXPLAIN SELECT * from llt_orders WHERE vendor_id in ( 13 , 44 )

    EXPLAIN SELECT * from llt_orders WHERE vendor_id > 13 and vendor_id < 44

    EXPLAIN SELECT * from orders WHERE vendor_id BETWEEN 13 and 44 

    这个命中索引
    EXPLAIN SELECT * from llt_orders WHERE vendor_id in ( 21 , 45 );

  • 相关阅读:
    Paxos算法简单陈述
    二段式提交和三段式提交
    Guava包学习--Hash
    JedisPool无法获得资源问题
    有料面试题之--Object里面的方法
    Spring常用jar包的功能
    线上日志分析与其他一些脚本
    Flutter-漸變色按鈕
    Flutter-自定義圖標或者選擇框
    Flutter-自定義圖片圖標
  • 原文地址:https://www.cnblogs.com/fengliang/p/13846554.html
Copyright © 2011-2022 走看看