镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[Bug]: Problem exporting an unsual index (IFNULL expression)  #640

Description

@alescan86

Describe the bug

I added this index to a table:

ALTER TABLE drafts
  ADD UNIQUE unique_draft (type,user,(IFNULL(touser,'_CHAT_'))) USING BTREE;

and when I try to export it fails with this error (on hosting phpmyadmin version 5.1.0, mysql is Percona 8.0.43-34):

Fatal error: Uncaught TypeError: str_replace(): Argument phpmyadmin/phpmyadmin#3 ($subject) must be of type array|string, null given in /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Context.php:608
Stack trace:
#0 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Context.php(608): str_replace()
phpmyadmin/phpmyadmin#1 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Components/Key.php(203): PhpMyAdmin\SqlParser\Context::escape()
phpmyadmin/phpmyadmin#2 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Component.php(74): PhpMyAdmin\SqlParser\Components\Key::build()
phpmyadmin/phpmyadmin#3 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Components/CreateDefinition.php(360): PhpMyAdmin\SqlParser\Component->__toString()
phpmyadmin/phpmyadmin#4 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Component.php(74): PhpMyAdmin\SqlParser\Components\CreateDefinition::build()
phpmyadmin/phpmyadmin#5 [internal function]: PhpMyAdmin\SqlParser\Component->__toString()
phpmyadmin/phpmyadmin#6 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Components/CreateDefinition.php(339): implode()
phpmyadmin/phpmyadmin#7 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Statements/CreateStatement.php(380): PhpMyAdmin\SqlParser\Components\CreateDefinition::build()
phpmyadmin/phpmyadmin#8 /var/www/html/phpMyAdmin/libraries/classes/Plugins/Export/ExportSql.php(2951): PhpMyAdmin\SqlParser\Statements\CreateStatement->build()
phpmyadmin/phpmyadmin#9 /var/www/html/phpMyAdmin/libraries/classes/Plugins/Export/ExportSql.php(1638): PhpMyAdmin\Plugins\Export\ExportSql->replaceWithAliases()
phpmyadmin/phpmyadmin#10 /var/www/html/phpMyAdmin/libraries/classes/Plugins/Export/ExportSql.php(2138): PhpMyAdmin\Plugins\Export\ExportSql->getTableDef()
phpmyadmin/phpmyadmin#11 /var/www/html/phpMyAdmin/libraries/classes/Export.php(813): PhpMyAdmin\Plugins\Export\ExportSql->exportStructure()
phpmyadmin/phpmyadmin#12 /var/www/html/phpMyAdmin/libraries/classes/Controllers/ExportController.php(549): PhpMyAdmin\Export->exportDatabase()
phpmyadmin/phpmyadmin#13 /var/www/html/phpMyAdmin/libraries/classes/Routing.php(186): PhpMyAdmin\Controllers\ExportController->index()
phpmyadmin/phpmyadmin#14 /var/www/html/phpMyAdmin/index.php(50): PhpMyAdmin\Routing::callControllerForRoute()
phpmyadmin/phpmyadmin#15 {main}
thrown in /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Context.php on line 608

On version 5.2.1 with mysql 8.0.41 it won't fails but the export result is like this

ALTER TABLE drafts ADD UNIQUE KEY unique_draft (type,user,(_CHAT_));

which is wrong.

How to Reproduce

Table structure is:

CREATE TABLE drafts (
  type enum('CHAT','MSGS') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  user varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  touser varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  text text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  date datetime NOT NULL
);
ALTER TABLE drafts ADD UNIQUE unique_draft (type, user,(IFNULL(touser,'_CHAT_'))) USING BTREE;

Expected behavior

I expect it to export the index like the original one

Screenshots

No response

Operating System

No response

Web Server

No response

Database Server

MySQL

Database version

No response

PHP version

No response

phpMyAdmin version

5.1.0

browser

No response

Additional context

No response

Activity

  1. williamdes commented on Feb 7, 2026

    @williamdes
    Member

    Thank you, we need to investigate if this is an issue with the parser or not

  2. changed the title [-][Bug]: Problem exporting an unsual index[/-] [+][Bug]: Problem exporting an unsual index (IFNULL expression) [/+] on Feb 7, 2026
  3. MoonE commented on Feb 7, 2026

    @MoonE
    Contributor

    It is a Parser issue.
    When parsing the opening parenthesis of the index expression(IFNULL(touser,'_CHAT_')), the Parser thinks it is a length like touser(6).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions