From 352c60d4cad48c9a18f6180fdaaf55fbc099f714 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Wed, 25 Sep 2013 06:43:15 +0530 Subject: [PATCH] bug #4102 ALTER TABLE ORDER BY and InnoDB --- ChangeLog | 1 + tbl_operations.php | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index cff1dfe592..1fa626ca59 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,7 @@ phpMyAdmin - ChangeLog - bug #4098 Default table tab is ignored - bug #4099 Server/library difference warning: setting is ignored - bug #4100 table tree group strategy +- bug #4102 ALTER TABLE ORDER BY and InnoDB 4.0.7.0 (2013-09-23) - bug #3993 Sorting in database overview with statistics doesn't work diff --git a/tbl_operations.php b/tbl_operations.php index f487ea97f0..36b7e56f1d 100644 --- a/tbl_operations.php +++ b/tbl_operations.php @@ -233,7 +233,30 @@ $columns = PMA_DBI_get_columns($GLOBALS['db'], $GLOBALS['table']); /** * Order the table */ -$response->addHTML(PMA_getHtmlForOrderTheTable($columns)); +require_once 'libraries/Index.class.php'; +$indexes = PMA_Index::getFromTable($GLOBALS['table'], $GLOBALS['db']); +$hasNotNullUniqueIdx = false; +foreach ($indexes as $name => $idx) { + if ($name == 'PRIMARY') { + $hasNotNullUniqueIdx = true; + } elseif (! $idx->getNonUnique()) { + $hasNotNullUniqueIdx = true; + foreach ($idx->getColumns() as $column) { + if ($column->getNull()) { + $hasNotNullUniqueIdx = false; + } + } + } + if ($hasNotNullUniqueIdx) { + break; + } +} +// `ALTER TABLE ORDER BY` does not make sense for InnoDB tables that contain +// a user-defined clustered index (PRIMARY KEY or NOT NULL UNIQUE index). +// InnoDB always orders table rows according to such an index if one is present. +if (! ($tbl_storage_engine == 'INNODB' && $hasNotNullUniqueIdx)) { + $response->addHTML(PMA_getHtmlForOrderTheTable($columns)); +} /** * Move table