I have a usernames
table with a username
string field, I have a "start with" query and trying both pattern and regex matching
SELECT username FROM usernames WHERE username LIKE 'foo%';
SELECT username FROM usernames WHERE username ~ '^foo';
I have a b-tree
index on the username
field and SET ENABLE_SEQSCAN =false;
, When I EXPLAIN
the abovementioned queries, the query planner uses SEQ_SCAN (Seq Scan)
I am using PostgreSQL 13.4 , tried VACUUM (VERBOSE, ANALYZE) usernames
and REINDEX TABLE usernames
too
What's wrong here?
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
CREATE INDEX usernames_idx_username ON "usernames" ("username");
SELECT
usernames.username
FROM
usernames
WHERE
usernames.username LIKE 'foo%'