Doctrine DBAL
  1. Doctrine DBAL
  2. DBAL-812

SchemaTool ignores multi-columns (composite) indexes when creating a foreign key

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.4.2
    • Fix Version/s: None
    • Component/s: Schema Managers
    • Labels:
    • Environment:
      MySQL

      Description

      When using the schema tool to generate the differences between the db and the entities, I notice the following:

      ALTER TABLE sales ADD CONSTRAINT FK_36D222EF603EE73 FOREIGN KEY (vid) REFERENCES vendor (id);
      CREATE INDEX IDX_36D222EF603EE73 ON sales (vid);

      Normally, it doesn't bother me, however I have had an existing composite index consists of (vid, submit). This leads to the redundant index IDX_36D222EF603EE73 and therefore forcing unnecessary overheads.

      It would be nice to have a mean to disable this from happening.

      The code in question can be found at https://github.com/doctrine/dbal/blob/594e326bd58d1d7af578f0dc3143655b9d119d45/lib/Doctrine/DBAL/Schema/Table.php#L543.

      A helpful member from #doctrine IRC also pointed out that it does not check the unique constraints also.

      Regards,

        Activity

        Peter Huynh created issue -
        Hide
        Marco Pivetta added a comment -

        Just a hint on this: looks like the current logic just checks hashed indexes, ignoring the "uniq" prefixed indexes to avoid duplicates.

        Show
        Marco Pivetta added a comment - Just a hint on this: looks like the current logic just checks hashed indexes, ignoring the "uniq" prefixed indexes to avoid duplicates.
        Marco Pivetta made changes -
        Field Original Value New Value
        Assignee Benjamin Eberlei [ beberlei ] Steve Müller [ deeky666 ]
        Marco Pivetta made changes -
        Priority Major [ 3 ] Minor [ 4 ]
        Marco Pivetta made changes -
        Summary SchmaTool ignores multi-columns (composite) indexes when creating a foreign key SchemaTool ignores multi-columns (composite) indexes when creating a foreign key
        Hide
        Steve Müller added a comment -

        Peter Huynh I get the point here. However after having a quick look into this it seems this behaviour exists for a good reason. See here: https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Schema/Index.php#L191-L195
        The question is how could this reasonable extended to fulfil the needs you explained. I am not entirely sure about this and this peace of code is rather sensitive and critical. I don't want to rush any assumptions here.

        Show
        Steve Müller added a comment - Peter Huynh I get the point here. However after having a quick look into this it seems this behaviour exists for a good reason. See here: https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Schema/Index.php#L191-L195 The question is how could this reasonable extended to fulfil the needs you explained. I am not entirely sure about this and this peace of code is rather sensitive and critical. I don't want to rush any assumptions here.
        Hide
        Peter Huynh added a comment -

        Hi Steve,

        I fully understand your reservation.

        Thanks for looking into things.

        Peter

        Show
        Peter Huynh added a comment - Hi Steve, I fully understand your reservation. Thanks for looking into things. Peter

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DBAL-812, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Steve Müller
            Reporter:
            Peter Huynh
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: