Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ORM abstraction for "WITH" clauses #10902

Closed
GuySartorelli opened this issue Aug 4, 2023 · 1 comment
Closed

Add ORM abstraction for "WITH" clauses #10902

GuySartorelli opened this issue Aug 4, 2023 · 1 comment

Comments

@GuySartorelli
Copy link
Member

GuySartorelli commented Aug 4, 2023

MySQL 8 supports WITH and WITH RECURSIVE statements, which opens up a whole load of opportunities.

The following methods could benefit from recursive queries (though some would have to be behind opt-in config flags for BC):

  • SiteTree::get_by_link()
  • SiteTree::relativeLink()
  • SiteTree::isOrphaned()
  • SiteTree::InSection()
  • SiteTree::getBreadcrumbItems()
  • SiteTree::NestedTitle()
  • SiteTree::Level()
  • SiteTree::getPageLevel()
  • SiteTree::getMenu()
  • Hierarchy::getAncestors()

Note that the above list was made after a very quick look at SiteTree and is far from exhaustive. I haven't looked pretty much anywhere else in core code.

Any usage of WITH clauses in core code will either need to be behind a condition checking if the current db driver supports it, or we'll have to explicitly say MySQL5.7 is no longer supported (it does go EOL in October 2023). But regardless of usage of the functionality, we can still provide an API for it, and anyone with an up-to-date db server can use it for their own purposes.

I've started a POC implementation here: GuySartorelli/silverstripe-framework@5...pulls/5/recursive-orm-queries

Acceptance criteria

  • An abstract way of using the WITH clause is added to the ORM. This abstraction should be implemented on SQLSelect and surfaced in DataQuery.
  • There's a compatible implementation for MySQL 8.
  • There's a way to check if that DB doesn't support the WITH clause or hasn't implemented the feature yet in their PHP library.
  • There's clear documentation on how to use the WITH abstraction for modules who can't assume what DB their end-project are using.
  • Create a follow up card to identify where we can use this in our own codebase.

Note

  • We're not sure if there's a sensible way to directly use the WITH clause from DataList directly. We'll discover this in the process of implementing this card and potentially spin up a follow up card if needed. DataList does not need its own abstraction layer at this stage. It can be added as a follow-up in the future if the need arises and a sensible implementation is identified.
  • Identify areas of the code that could be improved with Common Table Expressions (aka WITH clauses) #10962 has been created as a follow-up for this.

PRs

@GuySartorelli GuySartorelli removed their assignment Aug 15, 2023
@maxime-rainville maxime-rainville added this to the Silverstripe CMS 5.2 milestone Aug 20, 2023
@GuySartorelli GuySartorelli self-assigned this Sep 11, 2023
@GuySartorelli GuySartorelli removed their assignment Sep 21, 2023
@GuySartorelli GuySartorelli removed their assignment Sep 26, 2023
@emteknetnz emteknetnz self-assigned this Sep 27, 2023
@emteknetnz
Copy link
Member

emteknetnz commented Oct 2, 2023

Linked PRs have been merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants