I have huge words table which I'm running LIKE query on:
create table words
(
id int,
word varchar
)
It works pretty long. Index doesn't help a lot, so I'm trying to partition it by word column:
create table words
(
id int,
word varchar
) partition by RANGE (word);
CREATE TABLE words_1 PARTITION OF words
FOR VALUES FROM ('a') TO ('n');
CREATE TABLE words_2 PARTITION OF words
FOR VALUES FROM ('n') TO ('z');
NOTE: Actually I'm planning to make 1 partition for each letter. Use only 2 of them for example simplicity.
So partitioning seems to work OK with equality and gt/lt operators:
explain
select * from words where word = 'abc'
Seq Scan on words_1 words (cost=0.00..25.88 rows=6 width=36)
Filter: ((word)::text = 'abc'::text)
explain
select * from words where word >= 'nth'
Seq Scan on words_2 words (cost=0.00..25.88 rows=423 width=36)
Filter: ((word)::text >= 'nth'::text)
But on LIKE queries it keeps scanning both partitions:
explain
select * from words where word LIKE 'abc%'
Append (cost=0.00..51.81 rows=12 width=36)
-> Seq Scan on words_1 (cost=0.00..25.88 rows=6 width=36)
Filter: ((word)::text ~~ 'abc'::text)
-> Seq Scan on words_2 (cost=0.00..25.88 rows=6 width=36)
Filter: ((word)::text ~~ 'abc'::text)
Is there a way to make partitioning work on LIKE queries?
Maybe is there another way to achieve what i want?
explain analyzeto make sure the table statistics are up to date.explain analyzesays scan of this table takes 25 ms out of 27