diff --git a/ChangeLog b/ChangeLog
index f6d55f8a2f..ddad813ada 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -52,6 +52,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 6a1e4216c0..1004e5a297 100644
--- a/tbl_operations.php
+++ b/tbl_operations.php
@@ -236,7 +236,30 @@ $response->addHTML('
');
/**
* 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