joris.vandyck@promani.be writes:
> It seems like the choice between using the full index (first case with
> integer) or using the index partly and then filtering manually (second case
> with smallint) should not depend on whether the random_id is defined as
> integer or smallint.
The reason for the plan change is that if "random_id" is smallint, then
"random_id > 11422" is a cross-type operator (int2 > int4), and btree_gin
lacks support for such operators. Fixing that is probably just a Small
Matter Of Programming, but I doubt it's very high on anyone's to-do list.
In the meantime, you might consider casting the comparison constant to
int2 explicitly if you want to make "random_id" be smallint; that is,
"random_id > 11422::smallint" would be indexable.
regards, tom lane