I recently switched to from using integer sequence IDs to UUIDs for primary keys in my rails 3 app using Postgresql, using a method similar to this method. As such, none of my tables have sequences, yet rails is still making (what I believe to be) unnecessary calls to select sequences when records are created. For example:
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 function pk_and_sequence_for, the relevant part of my schema is:
t.uuid "id", :null => false, :primary => true
The uuid type is just a 32 char.
Could anyone enlighten me with an elegant way to prevent rails from making this query? (Or explain why it is necessary). Thanks.