V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
ffw5b7
V2EX  ›  问与答

求助:sql 优化

  •  1
     
  •   ffw5b7 · 2021-05-31 15:36:48 +08:00 · 499 次点击
    这是一个创建于 1279 天前的主题,其中的信息可能已经有所发展或是发生改变。
    select
    r.uuid as recruitUuid,
    r.project_name as projectName,
    r.work_type as workType,
    r.user_name as name,
    r.certification_status as certificationStatus,
    r.team_status as teamStatus,
    r.user_phone as userPhone,
    r.recruit_num as invite,
    r.price as price,
    r.description as description,
    r.detail_site as projectAddress,
    r.create_time as createTime,
    r.top_flag as topFlag,
    r.release_type as releaseType,
    r.bind_phone as bindPhone,
    r.is_help_wanted as isHelpWanted,
    r.modify_time as modifyTime
    from
    recruit r
    where
    r.del_flag = 0
    order by
    r.top_flag desc ,
    (
    case
    r.is_help_wanted when '1' then 0
    else 1
    end ) asc,
    LOCATE('深圳市', detail_site) desc,
    LOCATE('广东',detail_site) desc,
    r.create_time desc
    limit 100


    is_help_wanted 和 detail_site 怎么建立索引。或者怎么优化关于这二个字段的排序?
    ffw5b7
        1
    ffw5b7  
    OP
       2021-05-31 15:43:06 +08:00
    CREATE INDEX index_order_by ON recruit (
    top_flag DESC,
    is_help_wanted,
    detail_site,
    create_time DESC
    );

    is_help_wanted,detail_site 导致失效, 谷歌搜了下 LOCATE 没有关于 LOCATE 索引方面的,
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1027 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 19:12 · PVG 03:12 · LAX 11:12 · JFK 14:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.