[BUG] False positive for BIGINT UNSIGNED AUTO_INCREMENT primary keys
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
The bug lives in the advanced PK checks of mysqltuner.pl, around the Surrogate Key Recommendation block near line 10666, where the check tests $columntype for auto_increment. Read the select_array query just above it, which pulls COLUMN_TYPE but not EXTRA, then reproduce with the CREATE TABLE in the issue against MySQL 8 to confirm EXTRA holds auto_increment. Done when the auto_increment test reads the EXTRA value and the false-positive message no longer appears for a BIGINT UNSIGNED AUTO_INCREMENT primary key.
Written by the indexing model from the issue text.
Description
Describe the bug
When checking primary keys in the "Surrogate Key Recommendation" section, MySQLTuner reports a false positive for tables using a recommended surrogate key:
BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY
The current implementation checks for auto_increment within COLUMN_TYPE, but in MySQL 8.x the AUTO_INCREMENT attribute is stored in the EXTRA column of information_schema.columns.
As a result, valid surrogate keys are incorrectly reported with:
Primary key 'id' is not a recommended surrogate key (BIGINT UNSIGNED AUTO_INCREMENT)
Execution Command
Please provide the exact command used to run MySQLTuner:
perl mysqltuner.pl --host xxx --user xxx --password xxx \
--dbstat --colstat --tbstat --sysstat --structstat --pfstat --idxstat --myisamstat \
--experimental --buffers \
--reportfile=mysqltuner.html
Environment info:
- MySQLTuner version: 2.9.2
- Database Server: MySQL
- Database Version: 8.0.36
- Operating System & Version: Ubuntu 26.04
- Perl version: v5.40.1
MySQLTuner Debug Output
Not included because the issue was identified through source code review and verification against information_schema.columns.
To Reproduce
Steps to reproduce the behavior if not fully captured by the debug output:
- Create Table:
CREATE TABLE tbl ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY(id) ); - Verify metadata:
SELECT COLUMN_NAME, DATA_TYPE, COLUMN_TYPE, EXTRA FROM information_schema.columns WHERE table_name = 'tbl' AND column_name = 'id'; - Result:
COLUMN_NAME = id DATA_TYPE = bigint COLUMN_TYPE = bigint unsigned EXTRA = auto_increment - Run MySQLTuner with
--reportfileoption. - Open the HTML report.
- Navigate to: Modeling > SQL Schema & Modeling Recommendations
Expected behavior
The following message should not be reported:
Primary key 'id' is not a recommended surrogate key (BIGINT UNSIGNED AUTO_INCREMENT)
Additional context
The current implementation validates AUTO_INCREMENT using COLUMN_TYPE:
$columntype !~ /auto_increment/i
However, AUTO_INCREMENT is exposed through the EXTRA column rather than COLUMN_TYPE in information_schema.columns.
The following patch resolves the false positive:
diff --git a/mysqltuner.pl b/mysqltuner.pl
index cf23ceb..f4409d0 100755
--- a/mysqltuner.pl
+++ b/mysqltuner.pl
@@ -10628,7 +10628,7 @@ having sum(if(c.column_key in ('PRI', 'UNI'), 1, 0)) = 0"
# Advanced PK checks
my @pkInfo = select_array(
-"SELECT c.TABLE_SCHEMA, c.TABLE_NAME, c.COLUMN_NAME, c.DATA_TYPE, c.COLUMN_TYPE
+"SELECT c.TABLE_SCHEMA, c.TABLE_NAME, c.COLUMN_NAME, c.DATA_TYPE, c.COLUMN_TYPE, c.EXTRA
FROM information_schema.columns c
JOIN information_schema.tables t USING (TABLE_SCHEMA, TABLE_NAME)
WHERE t.TABLE_TYPE = 'BASE TABLE'
@@ -10642,13 +10642,14 @@ WHERE t.TABLE_TYPE = 'BASE TABLE'
("Schema,Table,Column,DataType,ColumnType,IssueType,Description");
foreach my $pk (@pkInfo) {
- my ( $schema, $table, $column, $datatype, $columntype ) = split /\t/,
+ my ( $schema, $table, $column, $datatype, $columntype, $extra ) = split /\t/,
$pk;
$schema //= '';
$table //= '';
$column //= '';
$datatype //= '';
$columntype //= '';
+ $extra //= '';
# PK Naming Convention
if ( $column ne 'id' && $column ne "${table}_id" ) {
@@ -10665,7 +10666,7 @@ WHERE t.TABLE_TYPE = 'BASE TABLE'
# Surrogate Key Recommendation
if ( $datatype !~ /int/i
|| $columntype !~ /unsigned/i
- || $columntype !~ /auto_increment/i )
+ || $extra !~ /auto_increment/i )
{
# Check if it might be a UUID
if ( $column =~ /uuid/i ) {
- Dominant language
- Perl
- Stars
- 9.5k
- Forks
- 1.3k
- Avg merge
- 10h 18m
- Merged PRs (30d)
- 10
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from major/MySQLTuner-perl
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
major/MySQLTuner-perl#992 ·
Maintainers usually reply within 1 day
-
fix(ci): enable Group Replication recovery SSL in multi-db-docker-env and fix DB_PASS resolution in test_ha.shMay be free again @jmrenouard claimed this 69 days ago, and no pull request is open. Open
major/MySQLTuner-perl#977 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
feat(ha): enhance MySQL InnoDB Cluster & Group Replication diagnosticsMay be free again @jmrenouard claimed this 69 days ago, and no pull request is open. Openenhancement PATCH DELIVERED
major/MySQLTuner-perl#976 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
feat(galera): add network queue, PK certification, and split-brain quorum diagnosticsMay be free again @jmrenouard claimed this 69 days ago, and no pull request is open. Openenhancement
major/MySQLTuner-perl#975 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
Dependency DashboardMay be free again @jmrenouard claimed this 99 days ago, and no pull request is open. OpenPATCH DELIVERED
major/MySQLTuner-perl#587 · 6 comments · 1 assignee ·
Maintainers usually reply within 1 day
All issues in major/MySQLTuner-perl
Similar issues
-
Add .gitattributes so share/skel keeps LF on a Windows git checkoutPossibly taken @sadhana-s-codez claimed this 1 day ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 85/100
PerlDancer/Dancer2#1854 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
bioconda/bioconda-recipes#70187 ·
Maintainers usually reply within 2 days
-
documentation Needs Triage
Difficulty 1/5 Under an hour Newbie friendliness 93/100
Maintainers usually reply within 1 day