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

[Improvement] Prevent db errors on index updates on classes rebuild #16871

Merged
merged 7 commits into from May 3, 2024

Conversation

lukadschaak
Copy link
Contributor

@lukadschaak lukadschaak commented Mar 28, 2024

Changes in this pull request

Resolves #13195

Long time ago, i stumbled upon the errors that MySQL based databases throw, when you try to add an index which is already there or to delete an index that is not there:

An exception occurred while executing a query: SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP INDEX 'p_index_name'; check that it exists

Some explaining can also be found in the connected issue.

This PR add existence checks for those indexes. Advantage: Cleaner solution, Disadvatage: Slightly more time consuming. (See screenshots).

I did not find any good ways to write tests for that, so i tried that on local machine with the setup explained in the System Requirements Docs. Tested with MySQL 8.3.0 and MariDB 10.11.5

Additional info

I created a Pimcore class car with a name and a sku attribute. I updated the class via the Admin backend and looked in the profiler which db queries were executed. Both time without changing the class attributes at all.

Database queries without refactoring
Bildschirmfoto vom 2024-03-28 09-46-18

Database queries with refactoring
Bildschirmfoto vom 2024-03-28 13-06-32

Copy link

github-actions bot commented Mar 28, 2024

Review Checklist

  • Target branch (11.2 for bug fixes, others 11.x)
  • Tests (if it's testable code, there should be a test for it - get help)
  • Docs (every functionality needs to be documented, see here)
  • Migration incl. install.sql (e.g. if the database schema changes, ...)
  • Upgrade notes (deprecations, important information, migration hints, ...)
  • Label
  • Milestone

@mcop1 mcop1 self-assigned this Apr 5, 2024
@lukadschaak
Copy link
Contributor Author

It seems like the pipeline did crash because of random 500er errors. The actions could not be loaded.

Could you please run it again @mcop1 or @wisconaut

Copy link
Contributor

@mcop1 mcop1 left a comment

Choose a reason for hiding this comment

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

Hello @lukadschaak ,

we would like to have your changes in the core and would value the error resilience above the performance impact.

But I noticed a problem while executing the command. E.g. here https://github.com/pimcore/pimcore/pull/16871/files#diff-38cc27289cd8997402eaa2b3921c32292050c33ff9ad2f59c5606c079bb35484R55
you use $columnName as parameter for indexDoesNotExist method. But it includes quotes for the identifier, therefore the method will return true even if the index exists. I think we should rather use $indexNameas a parameter? What do you think?

If you agree, could you please check the other occurrences too? Thank you for your efforts!

@mcop1 mcop1 added this to the 11.3.0 milestone Apr 12, 2024
Copy link

github-actions bot commented Apr 22, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@lukadschaak
Copy link
Contributor Author

@mcop1 Thanks a lot for your review!

You are absolutely right with your suggestion. Maybe you can take a look at the last commits from me. I followed your sugestion and used $indexName.

I also renamed the other occourance as well, because it looks more suitable for me. But this could be easily reverted.

Also I want to mention, that I was not able to check the multicolumn cases. I don't know how to reproduce this.

@lukadschaak
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@lukadschaak lukadschaak force-pushed the feature/db-errors-on-index-updates branch from ee91afd to afd06cb Compare April 22, 2024 13:50
Copy link

sonarcloud bot commented Apr 22, 2024

Quality Gate Passed Quality Gate passed

Issues
2 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
1.8% Duplication on New Code

See analysis details on SonarCloud

@mcop1
Copy link
Contributor

mcop1 commented May 3, 2024

Looks good to me, thank you again!

@mcop1 mcop1 merged commit fa5c318 into pimcore:11.x May 3, 2024
18 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators May 3, 2024
@lukadschaak lukadschaak deleted the feature/db-errors-on-index-updates branch May 3, 2024 14:39
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.

[Improvement]: Prevent db errors on index updates on classes rebuild
4 participants