From c7fdbffa0d3d28baaf18caef9c5d7de0fd7d1570 Mon Sep 17 00:00:00 2001
From: unknown <gluh@gluh.mysql.r18.ru>
Date: Thu, 3 Mar 2005 19:20:16 +0300
Subject: [PATCH] Fix for bug #8164: subquery with INFORMATION_SCHEMA.COLUMNS,
 100 % CPU

---
 mysql-test/r/information_schema.result | 7 +++++++
 mysql-test/t/information_schema.test   | 9 +++++++++
 sql/sql_show.cc                        | 4 ++++
 3 files changed, 20 insertions(+)

diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result
index 121de94056..8e49a3df4c 100644
--- a/mysql-test/r/information_schema.result
+++ b/mysql-test/r/information_schema.result
@@ -631,3 +631,10 @@ TABLES	UPDATE_TIME	datetime
 TABLES	CHECK_TIME	datetime
 ROUTINES	CREATED	datetime
 ROUTINES	LAST_ALTERED	datetime
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES A
+WHERE NOT EXISTS 
+(SELECT * FROM INFORMATION_SCHEMA.COLUMNS B
+WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA
+AND A.TABLE_NAME = B.TABLE_NAME);
+COUNT(*)
+0
diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test
index 86d7bad76b..9ff0b1fdf6 100644
--- a/mysql-test/t/information_schema.test
+++ b/mysql-test/t/information_schema.test
@@ -400,3 +400,12 @@ information_schema.columns
 where data_type = 'longtext';
 select table_name, column_name, data_type from information_schema.columns
 where data_type = 'datetime';
+
+#
+# Bug #8164  subquery with INFORMATION_SCHEMA.COLUMNS, 100 % CPU
+#
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES A
+WHERE NOT EXISTS 
+(SELECT * FROM INFORMATION_SCHEMA.COLUMNS B
+  WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA
+  AND A.TABLE_NAME = B.TABLE_NAME);
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 1339b5e5ed..7a4ee9f5de 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -1649,6 +1649,10 @@ bool uses_only_table_name_fields(Item *item, TABLE_LIST *table)
                                strlen(item_field->field_name), 0)))
       return 0;
   }
+  if (item->type() == Item::SUBSELECT_ITEM &&
+      !item->const_item())
+    return 0;
+
   return 1;
 }
 
-- 
2.30.9