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

Ignore index prefix lengths for spatial indexes #3970

Closed

Conversation

ksaveras
Copy link

@ksaveras ksaveras commented Apr 21, 2020

Q A
Type improvement
BC Break no
Fixed issues #3561

Summary

MySQL spatial indexes do not support index lengths and this check should be skipped.
If there are MSSQL or PGSQL experts - please comment.

This PR skips index lengths check if both indexes have a spatial flag.

I.e. when an index is created, MySQL 5.7 creates with 32 bytes prefix length. AWS Aurora (MySQL 5.7 compatible) - 24 bytes prefix length.

@ksaveras ksaveras marked this pull request as draft April 25, 2020 08:28
@ksaveras ksaveras marked this pull request as ready for review April 25, 2020 08:28
cesurapp
cesurapp previously approved these changes May 13, 2020
Copy link

@cesurapp cesurapp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This development works for the spatial index.

@Apostropher
Copy link

Is there an ETA for when this will be merged? I'm currently waiting for this fix.

@greg0ire
Copy link
Member

greg0ire commented Jul 1, 2020

Not a PG expert, but it looks like this wouldn't be handled by flags in PG since the syntax, which requires the PostGis extension is :

CREATE INDEX nyc_census_blocks_geom_idx
  ON nyc_census_blocks
  USING GIST (geom);

flags are apparently supposed to appear between CREATE and INDEX.

PostGIS does not seem to be supported though (and will never be?)

@greg0ire
Copy link
Member

greg0ire commented Jul 1, 2020

Also, the linked issue shows that this piece of code is responsible for the length appearing:

$v['flags'] = ['SPATIAL'];
}
$v['length'] = $v['sub_part'] ?? null;

Why not change it so that the length is not set at all in case the index is spatial?

lib/Doctrine/DBAL/Schema/Index.php Outdated Show resolved Hide resolved
tests/Doctrine/Tests/DBAL/Schema/IndexTest.php Outdated Show resolved Hide resolved
tests/Doctrine/Tests/DBAL/Schema/IndexTest.php Outdated Show resolved Hide resolved
yield ['spatial', 'spatial', [], [], true];
yield ['spatial', 'spatial', [], [32], true];
yield ['spatial', 'spatial', [32], [32], true];
yield ['spatial', 'spatial', [32], [24], true];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a data provider for a spatial index test, why do we care about testing the length comparison? If the logic of comparison of the flags and lengths needs to be tested, it's better to do it in a separate test that would not get too much into the details of why the lengths or flags mismatch.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are testing if the method isFullfilledBy works as expected in different cases. When spatial index created or migration is generated (or checked) on different platforms: MySQL, AWS Aurora MySQL.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine but some of these different cases are better to be implemented as a separate test method. Otherwise, if someone breaks the length comparison logic and testFulfilledSpatialIndex() fails, it will be misleading feedback from the test suite.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a text key on data providers would also give more information to a failing test with a data row, but separate test cases provide a more contextual structure for the test class.

@ksaveras
Copy link
Author

ksaveras commented Jul 3, 2020

Also, the linked issue shows that this piece of code is responsible for the length appearing:

$v['flags'] = ['SPATIAL'];
}
$v['length'] = $v['sub_part'] ?? null;

Why not change it so that the length is not set at all in case the index is spatial?

I like this idea.

lib/Doctrine/DBAL/Schema/Index.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Schema/Index.php Outdated Show resolved Hide resolved
@greg0ire
Copy link
Member

@ksaveras 2.10.x only accepts security fixes now, retargeting to 2.11.x .

@greg0ire greg0ire changed the base branch from 2.10.x to 2.11.x September 26, 2020 09:51
@greg0ire
Copy link
Member

greg0ire commented Sep 26, 2020

git fetch
git rebase origin/2.11.x
composer install
vendor/bin/phpcbf

should help with the cs issues.

@ksaveras
Copy link
Author

@ksaveras

This comment has been minimized.

@greg0ire

This comment has been minimized.

@greg0ire

This comment has been minimized.

@greg0ire
Copy link
Member

greg0ire commented Sep 26, 2020

Do you want to add this globally for all contributors?

We already have a contributing guide, but no link to it, which sounds a bit weird. Good point, I will make a PR later to address that.

UPD: See #4299

@greg0ire
Copy link
Member

Travis got confused with the 2 PRs, let's close and reopen to trigger a new build

@greg0ire greg0ire closed this Sep 26, 2020
@greg0ire greg0ire reopened this Sep 26, 2020
Copy link
Member

@morozov morozov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I misunderstood the boolean logic being tested when requested the changes in #3970 (comment). Makes sense.

lib/Doctrine/DBAL/Schema/Index.php Outdated Show resolved Hide resolved
@morozov
Copy link
Member

morozov commented Sep 26, 2020

[…] when an index is created, MySQL 5.7 creates with 32 bytes prefix length. AWS Aurora (MySQL 5.7 compatible) - 24 bytes prefix length.

While the patch addresses this issue, I can hardly see it being a bug. DBAL does not claim the support for portability between MySQL and Aurora, in which case it would be a bug.

I don't know enough about how index length is applied to spatial indexes, so it is possible that it's a breaking change while the primary focus of 2.11.1 is to fix the existing BC breaks before the 3.0 release.

UPD: as pointed out in the documentation mentioned in #3561.

Column prefix lengths are prohibited. The full width of each column is indexed.

So it is sort of a bug.

@morozov morozov added this to the 3.0.0 milestone Sep 26, 2020
@morozov
Copy link
Member

morozov commented Sep 26, 2020

@ksaveras what does MySQL report as the spatial index sub_part if the column length is prohibited? Should we, instead of changing the comparison logic, check the introspection logic?

if (strpos($v['index_type'], 'FULLTEXT') !== false) {
$v['flags'] = ['FULLTEXT'];
} elseif (strpos($v['index_type'], 'SPATIAL') !== false) {
$v['flags'] = ['SPATIAL'];
}
$v['length'] = $v['sub_part'] ?? null;

E.g. not use sub_part to populate the length of a spatial index.

@morozov morozov removed this from the 3.0.0 milestone Sep 26, 2020
@morozov morozov changed the base branch from 2.11.x to 2.12.x November 29, 2020 21:37
@ottaviano
Copy link
Contributor

Hi, we have the same issue. How can we help getting merged this PR?

@morozov
Copy link
Member

morozov commented Jan 18, 2021

@ottaviano this patch requires integration testing. This may shed some light on how #3970 (comment) should be addressed.

@morozov
Copy link
Member

morozov commented Mar 17, 2021

Superseded by #4525.

@morozov morozov closed this Mar 17, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants