Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[BUG] False positive for BIGINT UNSIGNED AUTO_INCREMENT primary keys

Aperta Adatta ai principianti
#1,007 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
mysql, perl, sql
Ambito
database

Direzione di ricerca

Il bug si trova nei controlli avanzati sulle chiavi primarie di mysqltuner.pl, intorno al blocco Surrogate Key Recommendation vicino alla riga 10666, dove il controllo su auto_increment verifica $columntype. Leggi la query select_array appena sopra, che recupera COLUMN_TYPE ma non EXTRA, poi riproduci con il CREATE TABLE dell'issue su MySQL 8 per confermare che EXTRA contiene auto_increment. È completato quando il test su auto_increment legge il valore di EXTRA e il messaggio di falso positivo non compare più per una chiave primaria BIGINT UNSIGNED AUTO_INCREMENT.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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 ) {
Lingua principale
Perl
Stelle
9.5k
Fork
1.3k
Merge medio
10h 18m
PR unite (30g)
10

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di major/MySQLTuner-perl

Tutte le issue di major/MySQLTuner-perl

Issue simili

Altre issue su Perl

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.