A SQL query searching for rows that satisfy Column1 <= X <= Column2 is very slow

后端 未结 12 1406
盖世英雄少女心
盖世英雄少女心 2021-01-11 16:27

I am using a MySQL DB, and have the following table:

CREATE TABLE SomeTable (
  PrimaryKeyCol BIGINT(20) NOT NULL,
  A BIGINT(20) NOT NULL,
  FirstX INT(11) N         


        
12条回答
  •  暖寄归人
    2021-01-11 17:04

    You need to add another index on LastX.

    The unique index FirstLastXPriority_Index (FirstX,LastX,P) represents the concatenation of these values, so it will be useless with the 'AND LastX >= ?' part of your WHERE clause.

提交回复
热议问题