DDC-546: New fetch mode EXTRA_LAZY for collections #5053

Closed
doctrinebot opened this Issue Apr 27, 2010 · 13 comments

2 participants

@doctrinebot

Jira issue originally created by user romanb:

A new fetch mode EXTRA_LAZY for one-to-many and many-to-many associations could have the following effects on PersistentCollection methods:

  • count() : Does not initialize the collection but issues a straight SQL count query.
  • remove($key) : Does not initialize the collection but issues straight SQL instead.
  • removeElement($element) : Does not initialize the collection but issues straight SQL instead.
  • contains($element) : Does not initialize the collection but issues straight SQL instead.
  • containsKey($key) : Does not initialize the collection but issues straight SQL instead.

This mode would usually be useful for (potentially) large collections.

We need to work out concrete use-case examples and implementation proposals before implementation.

The semantics of the mentioned methods with EXTRA_LAZY need to be carefully worked out, i.e. what happens to already managed instances in case of the remove operations and stuff like that.

@doctrinebot

Comment created by mjh_ca:

Wow, this is an excellent idea. I was just thinking how it is unfortunate that there aren't ways to manipulate large collections without resorting to DQL.

If nothing else, having access to a count() would be particularly great.

@doctrinebot

Comment created by romanb:

@Marc: You might then also be interested in a related ticket: http://www.doctrine-project.org/jira/browse/[DDC-547](http://www.doctrine-project.org/jira/browse/DDC-547)

This would basically allow you to craft special implementations that inherit from PersistentCollection that are "optimized" in some way for a specific association (i.e. write your own custom SQL query when count() is invoked). Your wrapper class is then used by Doctrine instead of the default one, thats the idea. Of course implementing such a custom collection and overriding methods needs to be done carefully to fully preserve the public API contract (PersistentCollection wrappers are supposed to be "invisible" to the user after all). So this would be an advanced feature. EXTRA_LAZY I think is a pretty easy feature, accessible for all users with no further knowledge required. It just means that the collection delays initialization even more, whereever possible, which is a good thing for large collections which you normally don't really want to load, yet it allows you to use the normal OO API of your domain model without resorting to special (DQL) queries.

@doctrinebot

Comment created by romanb:

Oh, I just saw you're watching that one already :) sorry for the noise

@doctrinebot

Comment created by romanb:

Rescheduling for beta3 as we're running out of time.

@doctrinebot

Comment created by @beberlei:

Additional features that have been requested by users:

  • Fetch entries in this collection in batches, i.e. only in 20 steps, issue a limit 0,21 and check if there is more

I don't know about the remove() and removeElement() operations, would they register with the UoW or directly execute the DELETE or UPDATE stements themselves?

@doctrinebot

Comment created by romanb:

Pushing back to beta4.

@doctrinebot

Comment created by romanb:

Moved to 2.1 due to lack of time for larger new stuff for 2.0.

@doctrinebot

Comment created by @beberlei:

https://github.com/doctrine/doctrine2/tree/[DDC-546](http://www.doctrine-project.org/jira/browse/DDC-546) first prototype implementation with tests.

Missing:

  • XML and YAML Mapping support.
  • Contains() support.
  • RemoveElement() support

Necessary for later scheduling (only make sense when persisting keys):

  • ContainsKey() support
  • RemoveKey() support
@doctrinebot

Comment created by @beberlei:

I updated the branch to include XML, YAML support, refactored a little bit and added contains() support.

The RemoveElement() support should be put into its own ticket that relates to the EntityManager#link() / EntityManager#unlink() functionality.

@doctrinebot

Comment created by @beberlei:

Implemented

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot

Comment created by @beberlei:

Usage would be inside a @OneToMany or @ManyToMany definition set

Annotations/XML:

fetch="EXTRA_LAZY"

YAML:

fetch: EXTRA_LAZY
@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.1 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment