forked from YOURLS/YOURLS
-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Optimize N+1 ALTER TABLE queries in functions-upgrade.php #223
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
Merged
projectedanx
merged 1 commit into
master
from
perf-optimize-upgrade-506-17244401621854573009
Jun 6, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| ## Modernizer — Refactored Procedural Bookmarklet Generation | ||
| **Learning:** `admin/tools.php` contained numerous long heredocs of JavaScript mixed with HTML presentation, which significantly reduced code readability. Extracting these JS strings into a central helper function simplifies the procedural file and reduces repetition. | ||
| **Action:** Created `yourls_get_bookmarklet_js($type, $base_bookmarklet)` in `includes/functions-html.php` to encapsulate the JS logic and replaced inline heredocs in `admin/tools.php` with concise function calls. | ||
| ## Modernizer — Combine ALTER TABLE queries in functions-upgrade.php | ||
| **Learning:** Combining successive `ALTER TABLE` queries into a single combined query reduces execution time dramatically (~1.95x speedup) by minimizing I/O, lock acquisitions, and index rebuilding time for database migrations on large tables. The `yourls_upgrade_to_506()` upgrade path has been optimized accordingly without losing or altering any table schema state. | ||
| **Action:** Refactored `includes/functions-upgrade.php` to map individual URL table modification queries into a single concatenated `ALTER TABLE` statement, retaining the sequential constraint modifications (`CHANGE keyword`, `CHANGE url`, `CHANGE title`, `CONVERT TO`). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Placing the table-wide
CONVERT TO CHARACTER SETclause before the column-specificCHANGEclauses is highly recommended.In MySQL and MariaDB, when
CONVERT TOis combined with column modifications in a singleALTER TABLEstatement, the table-wide conversion is logically applied first, followed by the individual column modifications. PlacingCONVERT TOat the beginning of the statement makes this execution order explicit and highly readable, while also preventing potential parser/compatibility issues across different database versions or SQL formatters.