UUID as primary key

38 views
Skip to first unread message

Venkatesh

unread,
Apr 7, 2015, 11:46:10 PM4/7/15
to plutu...@googlegroups.com
Hi

We are using UUID as the primary key in our application. We wanted to change the plutus tables to use UUID as the primary key. We have changed the migration to

class CreatePlutusTables < ActiveRecord::Migration
  def self.up
    create_table :plutus_accounts, id: :uuid do |t|
      t.string :name
      t.string :type
      t.boolean :contra

      t.timestamps
    end
    add_index :plutus_accounts, [:name, :type]

    create_table :plutus_entries, id: :uuid do |t|
      t.string :description
      t.integer :commercial_document_id
      t.string :commercial_document_type

      t.timestamps
    end
    add_index :plutus_entries, [:commercial_document_id, :commercial_document_type], :name => "index_entries_on_commercial_doc"

    create_table :plutus_amounts, id: :uuid do |t|
      t.string :type
      t.uuid :account_id
      t.uuid :entry_id
      #t.references :account
      #t.references :entry
      t.decimal :amount, :precision => 20, :scale => 10
    end
    add_index :plutus_amounts, :type
    add_index :plutus_amounts, [:account_id, :entry_id]
    add_index :plutus_amounts, [:entry_id, :account_id]
  end

  def self.down
    drop_table :plutus_accounts
    drop_table :plutus_entries
    drop_table :plutus_amounts
  end
end

It seems things are fine. We were wondering if there anything to watch out for?

Thanks,

Venkatesh

mbulat

unread,
Apr 8, 2015, 10:14:45 AM4/8/15
to plutu...@googlegroups.com
No specific issues that I know of. The only thing would be any standard issues with query and write performance of UUID versus integer, which would be specific to the database and UUID implementation. You might want to try and determine what type of report queries you'll be running, then generating lots of data and test your workloads to make sure you get reasonable performance. My guess is that only if your dataset is really large or under very high load would you notice any issues.

Venkatesh

unread,
Apr 8, 2015, 10:41:52 AM4/8/15
to plutu...@googlegroups.com
Thank you very much. We just wanted to make sure. We have factored in the potential performance issues and we expect no major issues in our use case.

Venkatesh 
Reply all
Reply to author
Forward
0 new messages