I’ve got a query:
select * from table where table.entity = '->...'
And when this query is run it returns no results. select * from table where table.entity like '->...'
does return a result.
At first I thought it was due to some non ascii character (entity
is a varchar(40)
) so I made a select ascii(substring(#,1))
query and ran through all 40 characters but they worked as expected, no special hidden characters.
The only difference between the =
and like
cases I can find is that the like
case uses a Seq Scan
and not an Index Scan
when I run explain analyze.
The index is CREATE INDEX table_entity ON public.table USING btree (entity NULLS FIRST, primary_key NULLS FIRST)
The string '->...'
has a fairly common to the database prefix, 315 of the 1043 records share the prefix. I’ve notice that this is an issue for all strings that start with ->
, and when running this query select * from table ORDER BY entity NULLS FIRST, primary_key NULLS FIRST
It seems to ignore the ->
and just focus on the values, so it would look like "->","Aaron","->Abagail",...
where it’s ordered but just ignoring the ->
Reindexing did not solve the issue.