zoukankan      html  css  js  c++  java
  • MYSQL where in (*,*,*,*,*,...................) 大量查询优化

    今天遇到的问题查询需要使用 where in ,虽然MySQL对于IN做了相应的优化,即将IN中的常量全部存储在一个数组里面,而且这个数组是排好序的。但是如果数值较多,产生的消耗也是比较大的。

    1:select id from t where num in(1,2,3) 对于连续的数值,能用between就不要用in了;

    2:使用join连接来替换。

    下面两段是我查资料时在评论区看到的,实际操作确实优化作用很大,特此记录:

    优化前:
    select docId from tab1 where word in (select word from tab1 where docId=123) group by docId limit 1000;
    优化后: select docId from (select word from tab1 where docId
    =123) as t2 join tab1 t on t.word=t2.word where t2.word is not null GROUP BY docId limit 1000
    既不回头,何必不忘; 既然无缘,何须誓言; 今日种种,逝水无痕; 明夕何夕,君已陌路;
  • 相关阅读:
    Go-结构体
    Go-指针
    Go-函数
    pycharm激活码
    python Ajax的使用
    python djangjo完整的实现添加的实例
    python 获取表单的三种方式
    python django ORM
    python django 模板语言循环字典
    python djangjo 文件上传
  • 原文地址:https://www.cnblogs.com/zyjfire/p/12924766.html
Copyright © 2011-2022 走看看