I added a migration to change the primary key of my existing db from the autogenerated system one to a composite key based on the following command:
add_index :listings, [:telephone, :name, :latitude, :longitude] , :unique=>true
My questions are:
the index generated by the command gonna be an integer? Since all the parameter fields are strings.
if I run this command after the db was created, does it regenerate the keys of all the rows or do I have to run a separate command for that?
does it make a difference when this command is run? If there were no rows in the table when this was run as opposed to running this after the table has rows?
Thanks
EDITED after reading the post below:====================================================
This is my model:
# Table name: listings
#
# id :integer not null, primary key
# name :string(50) default("ERROR:Not Available"), not null
# telephone :string(15) default("ERROR:Not Available"), not null
# latitude :string(15) default("ERROR:Not Available"), not null
# longitude :string(15) default("ERROR:Not Available"), not null
# avatar :string(30) default("Not Available")
So as you can see the primary key is the id, autogenerated by the system When I added the command above what exactly does that do then? I thought it changed the id field so that its an integer generated based on the 4 column values.
As you can guess, there can be mor than 2 people with the same names. So the only true way to guarantee uniqueness here is to create some sort of index based on the 4 columns.
By using the command above, am I doing the right thing? Will that work to speed up queries?