Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

[BUG] False positive for BIGINT UNSIGNED AUTO_INCREMENT primary keys

Abierto Apto para principiantes
#1,007 0 comentarios 0 reacciones 0 asignados Ver en GitHub

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
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
mysql, perl, sql
Área
database

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

bug

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:

  1. Create Table:
    CREATE TABLE tbl (
      id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
      PRIMARY KEY(id)
    );
    
  2. Verify metadata:
    SELECT
      COLUMN_NAME,
      DATA_TYPE,
      COLUMN_TYPE,
      EXTRA
    FROM information_schema.columns
    WHERE table_name = 'tbl'
      AND column_name = 'id';
    
  3. Result:
    COLUMN_NAME = id
    DATA_TYPE   = bigint
    COLUMN_TYPE = bigint unsigned
    EXTRA       = auto_increment
    
  4. Run MySQLTuner with --reportfile option.
  5. Open the HTML report.
  6. 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

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de major/MySQLTuner-perl

Todos los issues de major/MySQLTuner-perl

Issues similares

Más issues de Perl

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.