mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Functional Indexes #7224
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @SerheyDolgushev on GitHub (Sep 15, 2023).
Feature Request
MySQL 8.0.13 and higher supports functional indexes. Similar functionality seems to be available in PostgreSQL for a while. But it is not supported in Doctrine yet. Is it a good idea to implement it?
Summary
Let's assume we have the following Article entity:
And the following migration will be generated for it:
Let's add some records:
Register
WEEKDAYDQL string function, and try to find all the articles published on Sunday. You will get SQL query similar to:And run
EXPLAINfor it:There is a very easy way to improve it by adding a functional index:
And the new execution plan is:
The current problems are:
ORM\Indexattribute:There is no column with name "expression:WEEKDAY(published_at)" on table "article".error onphp bin/console make:migration.php bin/console doctrine:migrations:diffreturns the following error:Column_name, but it hasExpression:So the main question is does it worth implementing function indexes at all?
@drmax24 commented on GitHub (Nov 15, 2024):
Any workaround guys? A way to suppress it or smth?
@katzendrama commented on GitHub (Jun 10, 2025):
Couldn´t you use a custom column definition for this and even increase compatibility to older DBs like this?
I think this could be an option for you...