小编A. *_*ser的帖子

使用索引优化SQLite3上的SQL查询

我正在尝试通过创建索引来优化SQL查询以获得最佳性能.

表定义

CREATE TABLE Mots (
  numero            INTEGER NOT NULL, 
  fk_dictionnaires integer(5) NOT NULL, 
  mot              varchar(50) NOT NULL, 
  ponderation      integer(20) NOT NULL,
  drapeau varchar(1) NOT NULL,
  CONSTRAINT pk_mots PRIMARY KEY(numero),
  CONSTRAINT uk_dico_mot_mots UNIQUE(fk_dictionnaires, mot),
  CONSTRAINT fk_mots_dictionnaires FOREIGN KEY(fk_dictionnaires) REFERENCES Dictionnaires(numero)
  );
Run Code Online (Sandbox Code Playgroud)

索引定义

CREATE INDEX idx_dictionnaires ON mots(fk_dictionnaires DESC);
CREATE INDEX idx_mots_ponderation ON mots(ponderation);
CREATE UNIQUE INDEX idx_mots_unique ON mots(fk_dictionnaires, mot);
Run Code Online (Sandbox Code Playgroud)

SQL查询:

SELECT numero, mot, ponderation, drapeau 
FROM mots 
WHERE mot LIKE 'ar%' 
   AND fk_dictionnaires=1 
   AND LENGTH(mot)>=4 
   ORDER BY ponderation DESC …
Run Code Online (Sandbox Code Playgroud)

sql indexing optimization performance

7
推荐指数
1
解决办法
4068
查看次数

标签 统计

indexing ×1

optimization ×1

performance ×1

sql ×1