Using Postgres 10.11.
Table schema:
create table "db"."table"
(
id varchar(4096) not null
constraint "db-table_pkey"
primary key,
etag varchar(255) not null,
jsondata jsonb not null
);
We found to be accidentally creating an index like this:
create index "something"
on "db"."table" (('id'::text),
(jsondata -> 'someOtherField'::text),
((jsondata -> 'someOtherField2'::text) = 'false'::jsonb));
And this query would not use the above index:
select *
FROM "db"."table"
where jsonData->'someOtherField' = '"value"'
AND jsonData->'someOtherField2' = 'false'
AND id = 'testid'
order by id
limit 5
Remaking the index like this solved the issue:
create index "something"
on "db"."table" ((id), -- JUST ID!!!
(jsondata -> 'someOtherField'::text),
((jsondata -> 'someOtherField2'::text) = 'false'::jsonb));
It seems we are not supposed to use single quotes on index column names. Can anyone tell me what the index was made on in the first part? Was it just made on the 'id' string constant? Could I even trigger that index with any query? Or are they the same index?