I recently switched from using integer identifiers to UUIDs for primary keys in my Rails 3 application using Postgresql using a method similar to this method . Thus, none of my tables have sequences, but Rails still makes (what I think) unnecessary calls to select sequences when creating records. For instance:
PK and serial sequence (1.3ms) SELECT attr.attname, seq.relname FROM pg_class seq, pg_attribute attr, pg_depend dep, pg_namespace name, pg_constraint cons WHERE seq.oid = dep.objid AND seq.relkind = 'S' AND attr.attrelid = dep.refobjid AND attr.attnum = dep.refobjsubid AND attr.attrelid = cons.conrelid AND attr.attnum = cons.conkey[1] AND cons.contype = 'p' AND dep.refobjid = '"posts"'::regclass
I believe this is generated by the pk_and_sequence_for function. The relevant part of my schema:
t.uuid "id", :null => false, :primary => true
The uuid type is just 32 char.
Can someone enlighten me with an elegant way to prevent Rails from this request? (Or explain why this is necessary). Thanks.
source share