arthurhsu / lovefield-ts

Lovefield TypeScript port: successor of google/lovefield
Apache License 2.0
47 stars 3 forks source link

FK and unique constraints should reuse same index when possible #33

Open arthurhsu opened 1 year ago

arthurhsu commented 1 year ago

Example schema var tableBuilder = new lf.schema.TableBuilder('Table'); tableBuilder. addColumn('employeeId', lf.Type.INTEGER). addUnique('uq_employeeId', ['employeeId']). addForeignKey('fkemployeeId', { local: 'employeeId', ref: 'Employee.id' }); var schema = tableBuilder.getSchema();

This schema will cause 2 indices to be generated for the same column, fkemployeeid and uq_employeeId. This seems wasteful and also inconsistent with what other SQL engines do. We can probably find a way to only generate one index instead.