admin管理员组文章数量:1401241
I'm learning SQL and I'm trying to create a partial index on one of my database tables using a LIKE clause. Although the index does get created successfully, when I check the query plan for a query that's supposed to utilize the index created, it shows that SQLite is scanning the entire table instead.
I tried using an IN Clause to accommodate all my LIKE regex matches, but that didn't work either.
The courses table contains the following columns (schema query below):
CREATE TABLE IF NOT EXISTS "courses" (
"id" INTEGER,
"department" TEXT NOT NULL,
"number" INTEGER NOT NULL,
"semester" TEXT NOT NULL,
"title" TEXT NOT NULL,
PRIMARY KEY("id")
);
I've written a query to create an index on the semester table as follows:
CREATE INDEX "course_semester" ON
"courses" ("semester")
WHERE 1=1
AND (
"semester" LIKE '%2023'
or "semester" LIKE '%2024'
)
This index gets created successfully.
However when I check the query plan for the below query, SQLite says it isn't using this index at all.
SELECT "department", "number", "title"
FROM "courses"
WHERE 1=1
AND "semester" = 'Fall 2023';
What do I do to resolve this ? I tried using an IN clause hardcoding 'Fall 2023' and 'Spring 2024' and that didn't work as well.
本文标签: sqlHow do I utilize a partial index created using a LIKE clause in SQLiteStack Overflow
版权声明:本文标题:sql - How do I utilize a partial index created using a LIKE clause in SQLite? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744244452a2596942.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论