V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
deepmindlab
V2EX  ›  程序员

SQL 优化 or 问题

  •  
  •   deepmindlab · 2020-03-24 10:32:25 +08:00 · 973 次点击
    这是一个创建于 1500 天前的主题,其中的信息可能已经有所发展或是发生改变。

    where aoc.ao_order_no = '1' or aoc.ao_airline_no = '1' or aoc.ao_extf_no = '1' or aoc.ao_origin_order_no = '1'

    如上,如果条件 aoc.ao_order_no = '1'为 true 时,后面的条件还执行吗?如果是未免性能肯定受到影响,该如何解决?

    RRRoger
        1
    RRRoger  
       2020-03-24 11:44:05 +08:00   ❤️ 1
    如果都建立索引的话,建议改成

    ```sql

    where aoc.ao_order_no = '1'

    union

    where aoc.ao_airline_no = '1'

    union

    where aoc.ao_extf_no = '1'

    union

    where aoc.ao_origin_order_no = '1'

    ```
    egfegdfr
        2
    egfegdfr  
       2020-03-24 11:45:21 +08:00
    会继续执行,他会把所有符合这 4 个条件的都查出来。
    优化的话,
    一个是 如果编号都是数字的话,尽量用 int 类型的,不用用字符串。
    第二 可以根据实际情况加索引
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2078 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 10:50 · PVG 18:50 · LAX 03:50 · JFK 06:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.