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

Support an option for ranking queries to use window functions #19646

Open
bx80 opened this issue Aug 19, 2022 · 0 comments
Open

Support an option for ranking queries to use window functions #19646

bx80 opened this issue Aug 19, 2022 · 0 comments
Assignees
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.

Comments

@bx80
Copy link
Contributor

bx80 commented Aug 19, 2022

Currently ranking queries in Matomo are generated using a iterative counter method, this works well in MySQL but isn't well supported for other database types and can suffer from performance issues.

MySQL 8.0+ introduces new window functions which offer standardization and improved performance for ranking queries by allowing query planner optimizations. Specifically the RANK() and ROW_NUMBER() functions can be used to replace counters.

Windows functions are only supported for MySQL in version 8.0+, so old style counter queries will still need to be generated for MySQL 5.5 - 5.7.

Suggested approach

  • Add a PDO adapter interface boolean option supportsWindowFunctions, the standard Matomo MySQL PDO adapter should return false. Future PDO adapters for alternative databases that support windows functions can return true.

  • Make the core/DataAccess/RankingQuery class aware of the PDO adapter being used (via dependency injection?)

  • Have the RankingQuery class check the PDO adapter supportsWindowFunctions option and either generate a counter style ranking query using existing code or generate a query using the new window functions.

  • Code using the RankingQuery class should not need to be aware of whether a counter or window function ranking query is being generated (note: the goals by page sub-query might be an exception to this).

  • There should be no change at all to ranking queries generated when using the standard Matomo MySQL PDO adapter.

  • A MySQL8 PDO adapter descendant of the standard MySQL PDO adapter could be created to override this option and allow window function usage on MySQL 8.

@bx80 bx80 added the Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. label Aug 19, 2022
@bx80 bx80 self-assigned this Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Projects
None yet
Development

No branches or pull requests

2 participants