[3.0] Puts an index prefix length outside the column's quoting - #9652
Open
albertlast wants to merge 1 commit into
Open
[3.0] Puts an index prefix length outside the column's quoting#9652albertlast wants to merge 1 commit into
albertlast wants to merge 1 commit into
Conversation
A column can be indexed by its first so many characters, and list_indexes reports that as part of the column, so table_sql was quoting "member_groups(48)" whole and naming a column that does not exist. MySQL refuses the CREATE TABLE it produced: ERROR 1072 (42000): Key column 'member_groups(48)' doesn't exist in table Every table with a prefixed index was affected, which on a stock forum is boards, members, messages and log_packages. Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
This was referenced Sep 6, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
On MySQL,
table_sql()returns SQL that MySQL will not accept for any table carrying an index on part of a column:ERROR 1072 (42000): Key column 'member_groups(48)' doesn't exist in tableA column can be indexed by its first so many characters, and
list_indexes()reports that the way MySQL states it, asmember_groups(48).table_sql()then quotes each index column whole:which puts the count inside the name and asks for a column called
member_groups(48). What MySQL wants is`member_groups`(48), with the count outside the quoting.Twelve indexes on a forum with nothing added to it are affected, and two of them are primary keys:
admin_info_filesidx_filenamefilename(191)boardsidx_member_groupsmember_groups(191)log_packagesfilename,idx_filename,idx_hashfilename(191),filename(15),sha256_hash(191)membersidx_active_real_name,idx_email_address_ci,idx_lngfile,idx_spoofdetector_name,idx_spoofdetector_name_idreal_name(191),email_address_ci(191),lngfile(30),spoofdetector_name(191)settingsPRIMARYvariable(191)themesPRIMARYvariable(191)Nothing in SMF calls
table_sql(), which is why this has gone unnoticed. It is public API, reachable through thedb_table_sqlalias inDatabaseApi::$db_function_map, so a mod using it to record or copy a table gets SQL it cannot run.PostgreSQL is unaffected: its
table_sql()asks the server for each index withpg_get_indexdef()rather than assembling one.How this was verified
Against a MySQL forum upgraded from the 2.1.7 baseline, by taking
Db::$db->table_sql('smf_boards')and running it into an empty database, which is the only thing the output is for:ERROR 1072, no table createdThe comparison is
SHOW CREATE TABLEon both, withAUTO_INCREMENT=removed since it records how many rows a table has held rather than its shape.Not reachable from the unit suite
table_sql()is a database driver method and needs a connection.Issues References (Fixes|Related|Closes)