8000 Useless join statements when using a discriminator map · Issue #5961 · doctrine/orm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Useless join statements when using a discriminator map #5961
Closed
@sh4bang

Description

@sh4bang

Hi !

I'm working in a big project in which I use a discriminatorMap to handle many entity type : Class Table Inheritance

If we have many mapped entity inside the discriminatorMap (over something like 61 in my case), it generate a MySQL error :

SQLSTATE[HY000]: General error: 1116 Too many tables; MySQL can only use 61 tables in a join`

The problem is that Doctrine add a join statement for each known entity, even if I don't ask him any field of any sub entity.

My closure that return a QueryBuilder (for my form type), in the repository :

public function getEntityTest()
    {
        return $this->getEntityManager()
            ->createQueryBuilder()
            ->select('t.id, t.slug')
            ->from('AcmeBackendCoreBundle:TestRoot', 't');
    }

Using the above QueryBuilder will generate that kind of SQL :

SELECT 
  t0_.id AS id0, 
  t0_.slug AS slug1 
FROM 
  test_root t0_ 
  LEFT JOIN test_sub1 t1_ ON t0_.id = t1_.id 
  LEFT JOIN test_sub2 t2_ ON t0_.id = t2_.id 

But I don't care about test_sub1 or test_sub2 entities... It makes no sense to use it in some cases.

Here is an easy sample to reproduce :

use Doctrine\ORM\Mapping as ORM;
/**
 * TestRoot
 *
 * @ORM\Entity
 * @ORM\Table(name="test_root")
 *
 * @InheritanceType("JOINED")
 * @DiscriminatorColumn(name="type", type="string")
 * @ORM\Entity(repositoryClass="Acme\BackendCoreBundle\Repository\TestRootRepository")
 * @DiscriminatorMap({
 *      "sub_e1" = "\Acme\BackendCoreBundle\Entity\TestSub1",
 *      "sub_e2" = "\Acme\BackendCoreBundle\Entity\TestSub2",
 * })
 */
class TestRoot
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var String
     *
     * @ORM\Column(name="slug", type="string")
     */
    private $slug = "default_slug";

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set slug
     *
     * @param string $slug
     * @return TestRoot
     */
    public function setSlug($slug)
    {
        $this->slug = $slug;

        return $this;
    }

    /**
     * Get slug
     *
     * @return string 
     */
    public function getSlug()
    {
        return $this->slug;
    }

TestSub1 entity (duplicate for TestSub2 ) :

use Doctrine\ORM\Mapping as ORM;
/**
 * TestSub1
 *
 * @ORM\Entity
 * @ORM\Table(name="test_sub1")
 */
class TestSub1 extends TestRoot
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var String
     *
     * @ORM\Column(name="specific1", type="string")
     */
    private $specific1;

    /**
     * Set specific1
     *
     * @param string $specific1
     * @return TestSub1
     */
    public function setSpecific1($specific1)
    {
        $this->specific1 = $specific1;

        return $this;
    }

    /**
     * Get specific1
     *
     * @return string 
     */
    public function getSpecific1()
    {
        ret
5C5D
urn $this->specific1;
    }
}

Stack Overflow I opened : here

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0