This content has been marked as final. Show 4 replies
A foreign key index is a specialized secondary index. The only additional benefit of a foreign key index is that integrity constraints are enforced (these are listed in the javadoc).
I'm not sure I understand your join example. If you want to join from Employee to Company, then you don't need a secondary index. You would do:
A secondary index on Employee.company_id is used to find all Employees in a given company, and (if you wish) to enforce foreign key constraints.
Company c = companies.get(employee.company_id);
Thanks for the reply. Probably the example was poor. How about this one:
Emp (id, name)
Comp (id, name)
where WorksFor is many to many.
Now option1 is building and index on WorksFor(emp_id) to access companies an employee works for.
and option2 is making a foreign key from WorksFor(emp_id) to Emp(id).
When we make a join between Emp and WorksFor on employee id, will there be an advantage from using one option over the other?