From f0e835ac09ca1ce85933fbfa2ba095fd07a067b8 Mon Sep 17 00:00:00 2001
From: "monty@hundin.mysql.fi" <>
Date: Fri, 15 Mar 2002 21:30:50 +0200
Subject: [PATCH] Fixed problem with WHERE key=const ORDER BY key DESC

---
 Docs/manual.texi           |  8 +++++++-
 myisam/ft_boolean_search.c |  4 ++--
 sql/ha_myisam.cc           | 12 ++++++------
 sql/sql_select.cc          | 11 ++++++-----
 sql/sql_union.cc           |  3 ++-
 5 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/Docs/manual.texi b/Docs/manual.texi
index 2b21820e77..a7e7d979c4 100644
--- a/Docs/manual.texi
+++ b/Docs/manual.texi
@@ -9869,6 +9869,9 @@ If you would like MySQL to start automatically, you can copy
 @file{support-files/mysql.server} to @file{/etc/init.d} and create a
 symbolic link to it named @file{/etc/rc3.d/S99mysql.server}.
 
+As Solaris doesn't support core files for @code{setuid()} applications,
+you can't get a core file from @code{mysqld} if you are using the
+@code{--user} option.
 
 @menu
 * Solaris 2.7::                 Solaris 2.7/2.8 Notes
@@ -14114,7 +14117,8 @@ though.
 @item --core-file
 Write a core file if @code{mysqld} dies.  For some systems you must also
 specify @code{--core-file-size} to @code{safe_mysqld}. @xref{safe_mysqld, ,
-@code{safe_mysqld}}.
+@code{safe_mysqld}}. Note that on some system like Solaris, you will
+not get a core file if you are also using the @code{--user} option.
 
 @item -h, --datadir=path
 Path to the database root.
@@ -48732,6 +48736,8 @@ Fixed wrong error value when doing a @code{SELECT} with an empty HEAP table.
 @item
 Use @code{ORDER BY column DESC} now sorts @code{NULL} values first.
 @item
+Fixed bug in @code{WHERE key_name='constant' ORDER BY key_name DESC}.
+@item
 Fixed bug in @code{SELECT DISTINCT ... ORDER BY DESC} optimization.
 @item
 Fixed bug in @code{... HAVING 'GROUP_FUNCTION'(xxx) IS [NOT] NULL}.
diff --git a/myisam/ft_boolean_search.c b/myisam/ft_boolean_search.c
index ddd4ef9efb..6038a988db 100644
--- a/myisam/ft_boolean_search.c
+++ b/myisam/ft_boolean_search.c
@@ -112,7 +112,7 @@ int FTB_WORD_cmp_list(void *v __attribute__((unused)), FTB_WORD **a, FTB_WORD **
 }
 
 void _ftb_parse_query(FTB *ftb, byte **start, byte *end,
-                          FTB_EXPR *up, uint depth)
+		      FTB_EXPR *up, uint depth)
 {
   byte        res;
   FTB_PARAM   param;
@@ -127,7 +127,7 @@ void _ftb_parse_query(FTB *ftb, byte **start, byte *end,
   param.prev=' ';
   while ((res=ft_get_word(start,end,&w,&param)))
   {
-    byte  r=param.plusminus;
+    int  r=param.plusminus;
     float weight= (float) (param.pmsign ? nwghts : wghts)[(r>5)?5:((r<-5)?-5:r)];
     switch (res) {
       case 1: /* word found */
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc
index 127519d20f..df55cdd003 100644
--- a/sql/ha_myisam.cc
+++ b/sql/ha_myisam.cc
@@ -583,14 +583,14 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param, bool optimize)
       thd->proc_info="Repair by sorting";
       statistics_done=1;
       error = mi_repair_by_sort(&param, file, fixed_name,
-          param.testflag & T_QUICK);
+				param.testflag & T_QUICK);
     }
     else
     {
       thd->proc_info="Repair with keycache";
       param.testflag &= ~T_REP_BY_SORT;
       error=  mi_repair(&param, file, fixed_name,
-          param.testflag & T_QUICK);
+			param.testflag & T_QUICK);
     }
     param.testflag=testflag;
     optimize_done=1;
@@ -725,10 +725,10 @@ bool ha_myisam::check_and_repair(THD *thd)
   {
     sql_print_error("Warning: Recovering table: '%s'",table->path);
     check_opt.flags=
-        (myisam_recover_options & HA_RECOVER_BACKUP ? T_BACKUP_DATA : 0)
-      | (marked_crashed                             ? 0 : T_QUICK)
-      | (myisam_recover_options & HA_RECOVER_FORCE  ? 0 : T_SAFE_REPAIR)
-      | T_AUTO_REPAIR;
+      ((myisam_recover_options & HA_RECOVER_BACKUP ? T_BACKUP_DATA : 0) |
+       (marked_crashed                             ? 0 : T_QUICK) |
+       (myisam_recover_options & HA_RECOVER_FORCE  ? 0 : T_SAFE_REPAIR) |
+       T_AUTO_REPAIR);
     if (repair(thd, &check_opt))
       error=1;
   }
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 71da3c9431..8e2ef3993e 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -4685,7 +4685,7 @@ join_read_prev_same(READ_RECORD *info)
 		   tab->ref.key_length))
   {
     table->status=STATUS_NOT_FOUND;
-    error= 1;
+    error= -1;
   }
   return error;
 }
@@ -7056,8 +7056,9 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
 	item_list.push_back(new Item_null());
       if (tab->ref.key_parts)
       {
-	item_list.push_back(new Item_string(table->key_info[tab->ref.key].name,strlen(table->key_info[tab->ref.key].name)));
-	item_list.push_back(new Item_int((int) tab->ref.key_length));
+	item_list.push_back(new Item_string(table->key_info[tab->ref.key].name,
+					    strlen(table->key_info[tab->ref.key].name)));
+	item_list.push_back(new Item_int((int32) tab->ref.key_length));
 	for (store_key **ref=tab->ref.key_copy ; *ref ; ref++)
 	{
 	  if (tmp2.length())
@@ -7069,13 +7070,13 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
       else if (tab->type == JT_NEXT)
       {
 	item_list.push_back(new Item_string(table->key_info[tab->index].name,strlen(table->key_info[tab->index].name)));
-	item_list.push_back(new Item_int((int) table->key_info[tab->index].key_length));
+	item_list.push_back(new Item_int((int32) table->key_info[tab->index].key_length));
 	item_list.push_back(new Item_null());
       }
       else if (tab->select && tab->select->quick)
       {
 	item_list.push_back(new Item_string(table->key_info[tab->select->quick->index].name,strlen(table->key_info[tab->select->quick->index].name)));
-	item_list.push_back(new Item_int((int) tab->select->quick->max_used_key_length));
+	item_list.push_back(new Item_int((int32) tab->select->quick->max_used_key_length));
 	item_list.push_back(new Item_null());
       }
       else
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 7d921d6e59..82a88633b6 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -126,8 +126,9 @@ int mysql_union(THD *thd, LEX *lex,select_result *result)
   }
   union_result->save_time_stamp=!describe;
 
-  for (sl=lex->select=&lex->select_lex;sl;sl=lex->select=sl->next)
+  for (sl= &lex->select_lex; sl; sl=sl->next)
   {
+    lex->select=sl;
     thd->offset_limit=sl->offset_limit;
     thd->select_limit=sl->select_limit+sl->offset_limit;
     if (thd->select_limit < sl->select_limit)
-- 
2.30.9