Support for Partial Indexes for PostgreSql and Sqlite#600
Support for Partial Indexes for PostgreSql and Sqlite#600deeky666 merged 8 commits intodoctrine:masterfrom
Conversation
|
Hello, thank you for creating this pull request. I have automatically opened an issue http://www.doctrine-project.org/jira/browse/DBAL-900 We use Jira to track the state of pull requests and the versions they got |
|
Hi, I know that Oracle also supports partial indexes too. |
|
Hey, I already had a look at all platforms supporting this feature and only Maybe you could point me to Oracle documentation mentioning those ? Also On a side-note, SQL Server do support partial indexes, but I did not To sum up, since I was not sure if this feature would be merged, I didn't PS: I forced push a few modification in the last few days. What is the |
|
Sorry pushed the wrong button ^^ |
The file does not exists anymore because it was renamed from |
|
Needs a rebase... |
|
Done ! Nothing major was changed. Thanks for your interest. To come back on other platforms support, I think we should first focus on this PR and add other platforms later on if there is any interest. Not try to do everything at once. |
|
Looks good to me, @deeky666? |
There was a problem hiding this comment.
Please use {@inheritdoc} for this DocBlock here
|
Any news regarding this feature? Would be nice to have :) |
Support for Partial Indexes was available in Doctrine 1 following http://www.doctrine-project.org/jira/browse/DC-82. This commit reintroduce support for Doctrine 2. We use the same syntax with an optionnal "where" attribute for Index and UniqueConstraint.
This coherent with what is done for Table. All platform specific things are grouped into an options array. Eventually flags should be migrated into options as well.
|
So I fixed the few things mentioned and rebased my work on master. I believe it is ready to be merged. |
|
I think this is good to go, but I'll have to defer pressing |
There was a problem hiding this comment.
No need for else here.
if ($this->supportsPartialIndexes() && $index->hasOption('where')) {
return ' WHERE ' . $index->getOption('where');
}
return '';|
Sure, I should have noticed those... fixed ! |
|
And don't forget to merge doctrine/orm#1027 as well, since it would not be very useful otherwise |
|
@PowerKiKi sure we have it in our minds ;) |
lib/Doctrine/DBAL/Schema/Table.php
Outdated
There was a problem hiding this comment.
He have another BC break here. @PowerKiKi can you please also mention this change in the UPGRADE.md?
There was a problem hiding this comment.
Please add an array typehint on the argument here
|
Both remarks were fixed. |
|
@PowerKiKi I am missing the schema introspection part for partial indexes in SQLite. As far as I know you can get the information from the system table |
There was a problem hiding this comment.
Hmmm you are also skipping SQL generation tests for getUniqueConstraintDeclarationSQL() and getCreateIndexSQL() which actually is supported...
There was a problem hiding this comment.
I actually get the following errors:
getIndexDeclarationSQL()- Doctrine\DBAL\DBALException: Operation 'Doctrine\DBAL\Platforms\SQLAnywherePlatform::getIndexDeclarationSQL' is not supported by platform.``
getIndexDeclarationSQL()- InvalidArgumentException: Can only create unique constraint declarations, no common index declarations with getUniqueConstraintDeclarationSQL().
getCreateIndexSQL()- passed !
So it seems, there is only getCreateIndexSQL() which could be tested. And since this test was entirely written by me and getCreateIndexSQL() is already tested elsewhere, I don't think we "lose" coverage, nor that the effort would be worth it. What do you think ?
|
Index options are now covered by unit tests. Regarding Sqlite, I already had look at it, and re-confirmed it. Unfortunately the state of Sqlite platform seems to be less well maintained. Not even speaking of partial indexes, but plain vanilla indexes already fail miserably the schema introspection. But it does not appear anywhere in unit tests AFAIK. When switching my current project to Sqlite all indexes are always deleted and re-created from scratch when doing things like I would actually consider dropping Sqlite support from this PR, and in another PR fix vanilla indexes first, and then re-consider the partial indexes. What do you think ? Also I am not sure how to unit tests against "real" database... what the best practice about it ? |
|
@PowerKiKi thanks for applying the changes and investigating concerning SQLite. I was not aware that SQLite fails the schema introspection on indexes so you might be right and we should defer that issue on another PR to move forward here. We need to reinvestigate support for other platforms anyway so yeah I'm fine with your suggestion to drop partial index support on SQLite for now. |
|
Btw concerning functional tests, have a look at schema manager functional tests. They cover real schema introspection test cases. |
|
I don't feel like squashing commits is required here: we'd lose valuable history IMO |
While technically it could work, the schema introspection of Sqlite platform has severe flaws preventing us to provide reliable support of partial (and non-partial) indexes for the moment.
|
So I just pushed the de-activation of Sqlite. As for squashing I don't have any preferences. What should we do ? |
|
@PowerKiKi no need to squash then. I'll merge as soon as Travis goes green :) Thank you. |
|
You're very welcome. You were very thorough while reviewing this PR. It's nice to see that code quality is an important factor for Doctrine. And I am glad we were able to fix everything that needed fixing. |
Support for Partial Indexes for PostgreSql and Sqlite
|
\o/ |
|
@PowerKiKi we got a serious problem here in PostgreSQL >= PostgreSQL < PostgreSQL >= This makes the comparator freak out -.- But that option will convert the original expression, too. I do not know how to retrieve the original definition. @Ocramius should we simply adjust our test suite to return the same result on all platform versions and leave the expression as "fragile"? |
|
This is DDL only, and for a quite complicated platform-specific version.
Fragile can be acceptable given that the feature is not mainstream and
generally user-agent-facing.
On 18 Jan 2017 1:15 a.m., "Steve Müller" <notifications@github.com> wrote:
@PowerKiKi <https://github.com/PowerKiKi> we got a serious problem here in
PostgreSQL >= 9.5. See #2565 <#2565>
The problem is revealed here
<https://github.com/doctrine/dbal/blob/master/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php#L356>.
Seems they have changed the decompilation algorithm for partial index
expressions.
*PostgreSQL < 9.5*
(((id IS NOT NULL) AND (name IS NULL)) AND (email IS NULL))
*PostgreSQL >= 9.5*
((id IS NOT NULL) AND (name IS NULL) AND (email IS NULL))
This makes the comparator freak out -.-
Question is what to do. pg_get_expr() takes a third argument pretty_print
which when set results in:
id IS NOT NULL AND name IS NULL AND email IS NULL
id IS NOT NULL AND name IS NULL AND email IS NULL
But that option will convert the original expression, too. I do not know
how to retrieve the original definition. @Ocramius
<https://github.com/Ocramius> should we simply adjust our test suite to
return the same result on all platform versions and leave the expression as
"fragile"?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#600 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAJakCMtPR1-ky2E0mxlD_KRnM58CNB_ks5rTVmpgaJpZM4B4uZe>
.
|

Support for Partial Indexes was available in Doctrine 1 following
http://www.doctrine-project.org/jira/browse/DC-82. This commit
reintroduce support for Doctrine 2. We use the same syntax with an
optionnal "where" attribute for Index and UniqueConstraint.
It is unit-tests covered and documented in manual.