QGIS form performance

It seems to be a bug in QGIS that has existed for some time. I've tested versions 2.18, 3.4 and 3.10.

When using a bigint as a primary key, QGIS will cast the primary key to a text field. This causes the index on the primary key to be skipped causing a huge slow down in large tables.

This does not happen with if the primary key is of type:

  • Int
  • serial
  • bigserial

So a workaround is to either using these field types as your primary key. Or to create an index cast to a text field if this is not possible:

create index on belmap.address USING btree (cast(stableid as text));

Bug report can be found on: https://github.com/qgis/QGIS/issues/34077