Simplify and optimize Postgres query for primary_keys()
#27961

jordanlewis wants to merge jordanlewis:simplify-postgres-primary-keys-v2 into rails:master

We do not currently have an analysis of these two commits