Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-2464

useless index for the middle table of many-to-many relationship


    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: Git Master
    • Fix Version/s: None
    • Component/s: Tools
    • Security Level: All
    • Labels:


      I have entity A and B, the relationship between A and B is many-to-many. which means Doctrine2 will generate a middle table called AB for me.

      entity A:

      class Station {
           * @ORM\ManyToMany(targetEntity="Fun", mappedBy="stations")
          protected $funs;

      entity B:

      class Fun {
           * @ORM\ManyToMany(targetEntity="Station", inversedBy="funs")
           * @ORM\JoinTable(name="stations_have_funs")
          protected $stations;

      the schema of middle table stations_have_funs:

      CREATE TABLE `stations_have_funs` (
        `fun_id` int(11) NOT NULL,
        `station_id` int(11) NOT NULL,
        PRIMARY KEY (`fun_id`,`station_id`),
        KEY `IDX_45C921911CA4BE49` (`fun_id`),
        KEY `IDX_45C9219121BDB235` (`station_id`),
        CONSTRAINT `FK_45C921911CA4BE49` FOREIGN KEY (`fun_id`) REFERENCES `funs` (`id`) ON DELETE CASCADE,
        CONSTRAINT `FK_45C9219121BDB235` FOREIGN KEY (`station_id`) REFERENCES `stations` (`id`) ON DELETE CASCADE
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

      I noticed that there are 2 useless index(fun_id and station_id). Since fun_id and station_id are the primary key of this table. Do we really need 2 extra/duplicated index ?


        There are no comments yet on this issue.


          • Assignee:
            beberlei Benjamin Eberlei
            scourgen scourgen
          • Votes:
            0 Vote for this issue
            2 Start watching this issue


            • Created: