[BUG] False positive for BIGINT UNSIGNED AUTO_INCREMENT primary keys
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
Línea de trabajo
El error está en las comprobaciones avanzadas de clave primaria de mysqltuner.pl, alrededor del bloque Surrogate Key Recommendation cerca de la línea 10666, donde la comprobación de auto_increment evalúa $columntype. Lee la consulta select_array justo encima, que obtiene COLUMN_TYPE pero no EXTRA, y luego reproduce con el CREATE TABLE del issue contra MySQL 8 para confirmar que EXTRA contiene auto_increment. Está terminado cuando la prueba de auto_increment lee el valor de EXTRA y el mensaje de falso positivo deja de aparecer para una clave primaria BIGINT UNSIGNED AUTO_INCREMENT.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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 ) {
- Lenguaje dominante
- Perl
- Estrellas
- 9.5k
- Forks
- 1.3k
- Merge medio
- 10 h 18 min
- PR fusionados (30 d)
- 10
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de major/MySQLTuner-perl
-
Dificultad 3/5 1-2 días Aptitud para principiantes 72/100
major/MySQLTuner-perl#992 ·
Los mantenedores suelen responder en 1 día
-
fix(ci): enable Group Replication recovery SSL in multi-db-docker-env and fix DB_PASS resolution in test_ha.shQuizá libre de nuevo @jmrenouard la tomó hace 69 días y no hay ningún pull request abierto. Abierto
major/MySQLTuner-perl#977 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
feat(ha): enhance MySQL InnoDB Cluster & Group Replication diagnosticsQuizá libre de nuevo @jmrenouard la tomó hace 69 días y no hay ningún pull request abierto. Abiertoenhancement PATCH DELIVERED
major/MySQLTuner-perl#976 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
feat(galera): add network queue, PK certification, and split-brain quorum diagnosticsQuizá libre de nuevo @jmrenouard la tomó hace 69 días y no hay ningún pull request abierto. Abiertoenhancement
major/MySQLTuner-perl#975 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Dependency DashboardQuizá libre de nuevo @jmrenouard la tomó hace 99 días y no hay ningún pull request abierto. AbiertoPATCH DELIVERED
major/MySQLTuner-perl#587 · 6 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de major/MySQLTuner-perl
Issues similares
-
Add .gitattributes so share/skel keeps LF on a Windows git checkoutPosiblemente ocupada @sadhana-s-codez la tomó hace 1 día. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
PerlDancer/Dancer2#1854 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 69/100
bioconda/bioconda-recipes#70187 ·
Los mantenedores suelen responder en 2 días
-
documentation Needs Triage
Dificultad 1/5 Menos de una hora Aptitud para principiantes 93/100
Los mantenedores suelen responder en 1 día