Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[BUG] False positive for BIGINT UNSIGNED AUTO_INCREMENT primary keys

オープン 初心者向け
#1,007 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
mysql, perl, sql
領域
database

調査の方向性

バグは mysqltuner.pl の高度な PK チェックにあり、10666 行目付近の Surrogate Key Recommendation ブロックで、auto_increment のチェックが $columntype を対象にしています。その直前の select_array クエリを読んでください。このクエリは COLUMN_TYPE を取得していますが、EXTRA は取得していません。その後、MySQL 8 で Issue の CREATE TABLE を実行して再現し、EXTRA に auto_increment が含まれることを確認してください。auto_increment のテストが EXTRA の値を読み取り、BIGINT UNSIGNED AUTO_INCREMENT の主キーに対して誤検出メッセージが表示されなくなれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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 ) {
主要言語
Perl
スター
9.5k
フォーク
1.3k
平均マージ
10時間 18分
マージ済み PR(30日)
10

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

major/MySQLTuner-perl のほかの issue

major/MySQLTuner-perl の issue をすべて見る

似ている issue

Perl の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。