Skip to content

Loading…

DDC-2464: useless index for the middle table of many-to-many relationship #3181

Open
doctrinebot opened this Issue · 0 comments

2 participants

@doctrinebot

Jira issue originally created by user scourgen:

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 stationshavefuns:

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(funid and station_id). Since fun_id and stationid are the primary key of this table. Do we really need 2 extra/duplicated index ?

@beberlei beberlei was assigned by doctrinebot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.