[Commits] bzr commit into Mariadb 5.2, with Maria 2.0:maria/5.2 branch (monty:2823)

Michael Widenius monty at askmonty.org
Sat Jul 17 01:41:49 EEST 2010


#At lp:maria/5.2 based on revid:igor at askmonty.org-20100713174523-mjvsvvp6ow8dc81x

 2823 Michael Widenius	2010-07-17
      Fix for LP#588251: doStartTableScan() result not checked.
      The issue was that we didn't always check result of ha_rnd_init() which caused a problem for handlers that returned an error in this code.
      - Changed prototype of ha_rnd_init() to ensure that we get a compile warning if result is not checked.
      - Added ha_rnd_init_with_error() that prints error on failure.
      - Checked all usage of ha_rnd_init() and ensure we generate an error message on failures.
      - Changed init_read_record() to return 1 on failure.
      modified:
        sql/create_options.cc
        sql/event_db_repository.cc
        sql/events.cc
        sql/filesort.cc
        sql/ha_partition.cc
        sql/ha_partition.h
        sql/handler.cc
        sql/handler.h
        sql/item_subselect.cc
        sql/log.cc
        sql/log_event.cc
        sql/log_event_old.cc
        sql/mysql_priv.h
        sql/opt_range.cc
        sql/records.cc
        sql/sql_acl.cc
        sql/sql_cursor.cc
        sql/sql_delete.cc
        sql/sql_help.cc
        sql/sql_plugin.cc
        sql/sql_select.cc
        sql/sql_servers.cc
        sql/sql_table.cc
        sql/sql_udf.cc
        sql/sql_update.cc
        storage/example/ha_example.cc
        storage/ibmdb2i/ha_ibmdb2i.cc

per-file messages:
  sql/create_options.cc
    Fixed wrong printf
  sql/event_db_repository.cc
    Check result from init_read_record()
  sql/events.cc
    Check result from init_read_record()
  sql/filesort.cc
    Check result from ha_rnd_init()
  sql/ha_partition.cc
    Check result from ha_rnd_init()
  sql/ha_partition.h
    Fixed compiler warning
  sql/handler.cc
    Added ha_rnd_init_with_error()
    Check result from ha_rnd_init()
  sql/handler.h
    Added ha_rnd_init_with_error()
    Changed prototype of ha_rnd_init() to ensure that we get a compile warning if result is not checked
  sql/item_subselect.cc
    Check result from ha_rnd_init()
  sql/log.cc
    Check result from ha_rnd_init()
  sql/log_event.cc
    Check result from ha_rnd_init()
  sql/log_event_old.cc
    Check result from ha_rnd_init()
  sql/mysql_priv.h
    init_read_record() now returns error code on failure
  sql/opt_range.cc
    Check result from ha_rnd_init()
  sql/records.cc
    init_read_record() now returns error code on failure
    Check result from ha_rnd_init()
  sql/sql_acl.cc
    Check result from init_read_record()
  sql/sql_cursor.cc
    Print error if ha_rnd_init() fails
  sql/sql_delete.cc
    Check result from init_read_record()
  sql/sql_help.cc
    Check result from init_read_record()
  sql/sql_plugin.cc
    Check result from init_read_record()
  sql/sql_select.cc
    Check result from ha_rnd_init()
    Print error if ha_rnd_init() fails.
  sql/sql_servers.cc
    Check result from init_read_record()
  sql/sql_table.cc
    Check result from init_read_record()
  sql/sql_udf.cc
    Check result from init_read_record()
  sql/sql_update.cc
    Check result from init_read_record()
  storage/example/ha_example.cc
    Don't return error on rnd_init()
  storage/ibmdb2i/ha_ibmdb2i.cc
    Removed not relevant comment
=== modified file 'sql/create_options.cc'
--- a/sql/create_options.cc	2010-05-12 17:56:05 +0000
+++ b/sql/create_options.cc	2010-07-16 22:41:44 +0000
@@ -583,9 +583,9 @@ my_bool engine_table_options_frm_read(co
   }
 
   if (buff < buff_end)
-    sql_print_warning("Table %`s was created in a later MariaDB version - "
+    sql_print_warning("Table '%s' was created in a later MariaDB version - "
                       "unknown table attributes were ignored",
-                      share->table_name);
+                      share->table_name.str);
 
   DBUG_RETURN(buff > buff_end);
 }

=== modified file 'sql/event_db_repository.cc'
--- a/sql/event_db_repository.cc	2010-04-08 12:10:05 +0000
+++ b/sql/event_db_repository.cc	2010-07-16 22:41:44 +0000
@@ -474,7 +474,8 @@ Event_db_repository::table_scan_all_for_
   READ_RECORD read_record_info;
   DBUG_ENTER("Event_db_repository::table_scan_all_for_i_s");
 
-  init_read_record(&read_record_info, thd, event_table, NULL, 1, 0, FALSE);
+  if (init_read_record(&read_record_info, thd, event_table, NULL, 1, 0, FALSE))
+    DBUG_RETURN(TRUE);
 
   /*
     rr_sequential, in read_record(), returns 137==HA_ERR_END_OF_FILE,
@@ -960,7 +961,9 @@ Event_db_repository::drop_events_by_fiel
     DBUG_VOID_RETURN;
 
   /* only enabled events are in memory, so we go now and delete the rest */
-  init_read_record(&read_record_info, thd, table, NULL, 1, 0, FALSE);
+  if (init_read_record(&read_record_info, thd, table, NULL, 1, 0, FALSE))
+    goto end;
+
   while (!ret && !(read_record_info.read_record(&read_record_info)) )
   {
     char *et_field= get_field(thd->mem_root, table->field[field]);
@@ -982,8 +985,9 @@ Event_db_repository::drop_events_by_fiel
     }
   }
   end_read_record(&read_record_info);
-  close_thread_tables(thd);
 
+end:
+  close_thread_tables(thd);
   DBUG_VOID_RETURN;
 }
 

=== modified file 'sql/events.cc'
--- a/sql/events.cc	2010-04-28 12:52:24 +0000
+++ b/sql/events.cc	2010-07-16 22:41:44 +0000
@@ -1214,7 +1214,12 @@ Events::load_events_from_db(THD *thd)
     DBUG_RETURN(TRUE);
   }
 
-  init_read_record(&read_record_info, thd, table, NULL, 0, 1, FALSE);
+  if (init_read_record(&read_record_info, thd, table, NULL, 0, 1, FALSE))
+  {
+    close_thread_tables(thd);
+    DBUG_RETURN(TRUE);
+  }
+
   while (!(read_record_info.read_record(&read_record_info)))
   {
     Event_queue_element *et;

=== modified file 'sql/filesort.cc'
--- a/sql/filesort.cc	2010-07-13 17:45:23 +0000
+++ b/sql/filesort.cc	2010-07-16 22:41:44 +0000
@@ -537,7 +537,8 @@ static ha_rows find_all_keys(SORTPARAM *
   if (! indexfile && ! quick_select)
   {
     next_pos=(uchar*) 0;			/* Find records in sequence */
-    file->ha_rnd_init(1);
+    if (file->ha_rnd_init_with_error(1))
+      DBUG_RETURN(HA_POS_ERROR);
     file->extra_opt(HA_EXTRA_CACHE,
 		    current_thd->variables.read_buff_size);
   }

=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc	2010-06-05 14:53:36 +0000
+++ b/sql/ha_partition.cc	2010-07-16 22:41:44 +0000
@@ -1661,7 +1661,7 @@ int ha_partition::copy_partitions(ulongl
     uint32 new_part;
 
     late_extra_cache(reorg_part);
-    if ((result= file->ha_rnd_init(1)))
+    if ((result= file->ha_rnd_init_with_error(1)))
       goto error;
     while (TRUE)
     {

=== modified file 'sql/ha_partition.h'
--- a/sql/ha_partition.h	2010-06-05 14:53:36 +0000
+++ b/sql/ha_partition.h	2010-07-16 22:41:44 +0000
@@ -1129,7 +1129,7 @@ public:
   virtual handlerton *partition_ht() const
   {
     handlerton *h= m_file[0]->ht;
-    for (int i=1; i < m_tot_parts; i++)
+    for (uint i=1; i < m_tot_parts; i++)
       DBUG_ASSERT(h == m_file[i]->ht);
     return h;
   }

=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2010-07-09 11:39:19 +0000
+++ b/sql/handler.cc	2010-07-16 22:41:44 +0000
@@ -2114,6 +2114,18 @@ int handler::ha_open(TABLE *table_arg, c
 }
 
 
+/* Initialize handler for random reading, with error handling */
+
+int handler::ha_rnd_init_with_error(bool scan)
+{
+  int error;
+  if (!(error= ha_rnd_init(scan)))
+    return 0;
+  table->file->print_error(error, MYF(0));
+  return error;
+}
+
+
 /**
   Read first row (only) from a table.
 
@@ -2133,9 +2145,11 @@ int handler::read_first_row(uchar * buf,
   if (stats.deleted < 10 || primary_key >= MAX_KEY ||
       !(index_flags(primary_key, 0, 0) & HA_READ_ORDER))
   {
-    (void) ha_rnd_init(1);
-    while ((error= ha_rnd_next(buf)) == HA_ERR_RECORD_DELETED) ;
-    (void) ha_rnd_end();
+    if ((!(error= ha_rnd_init(1))))
+    {
+      while ((error= ha_rnd_next(buf)) == HA_ERR_RECORD_DELETED) ;
+      (void) ha_rnd_end();
+    }
   }
   else
   {

=== modified file 'sql/handler.h'
--- a/sql/handler.h	2010-06-05 14:53:36 +0000
+++ b/sql/handler.h	2010-07-16 22:41:44 +0000
@@ -1327,7 +1327,7 @@ public:
   }
   /* This is called after index_init() if we need to do a index scan */
   virtual int prepare_index_scan() { return 0; }
-  int ha_rnd_init(bool scan)
+  int ha_rnd_init(bool scan) __attribute__ ((warn_unused_result))
   {
     int result;
     DBUG_ENTER("ha_rnd_init");
@@ -1342,6 +1342,7 @@ public:
     inited=NONE;
     DBUG_RETURN(rnd_end());
   }
+  int ha_rnd_init_with_error(bool scan) __attribute__ ((warn_unused_result));
   int ha_reset();
   /* Tell handler (not storage engine) this is start of a new statement */
   void ha_start_of_new_statement()

=== modified file 'sql/item_subselect.cc'
--- a/sql/item_subselect.cc	2010-06-01 19:52:20 +0000
+++ b/sql/item_subselect.cc	2010-07-16 22:41:44 +0000
@@ -2070,7 +2070,8 @@ int subselect_uniquesubquery_engine::sca
   if (table->file->inited)
     table->file->ha_index_end();
  
-  table->file->ha_rnd_init(1);
+  if (table->file->ha_rnd_init_with_error(1))
+    DBUG_RETURN(1);
   table->file->extra_opt(HA_EXTRA_CACHE,
                          current_thd->variables.read_buff_size);
   table->null_row= 0;

=== modified file 'sql/log.cc'
--- a/sql/log.cc	2010-07-09 11:39:19 +0000
+++ b/sql/log.cc	2010-07-16 22:41:44 +0000
@@ -412,7 +412,7 @@ bool Log_to_csv_event_handler::
   need_close= TRUE;
 
   if (table->file->extra(HA_EXTRA_MARK_AS_LOG_TABLE) ||
-      table->file->ha_rnd_init(0))
+      table->file->ha_rnd_init_with_error(0))
     goto err;
 
   need_rnd_end= TRUE;
@@ -563,7 +563,7 @@ bool Log_to_csv_event_handler::
   need_close= TRUE;
 
   if (table->file->extra(HA_EXTRA_MARK_AS_LOG_TABLE) ||
-      table->file->ha_rnd_init(0))
+      table->file->ha_rnd_init_with_error(0))
     goto err;
 
   need_rnd_end= TRUE;

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2010-06-16 10:58:56 +0000
+++ b/sql/log_event.cc	2010-07-16 22:41:44 +0000
@@ -8920,10 +8920,10 @@ record_compare_exit:
 /**
   Locate the current row in event's table.
 
-  The current row is pointed by @c m_curr_row. Member @c m_width tells how many 
-  columns are there in the row (this can be differnet from the number of columns 
-  in the table). It is assumed that event's table is already open and pointed 
-  by @c m_table.
+  The current row is pointed by @c m_curr_row. Member @c m_width tells
+  how many columns are there in the row (this can be differnet from
+  the number of columns in the table). It is assumed that event's
+  table is already open and pointed by @c m_table.
 
   If a corresponding record is found in the table it is stored in 
   @c m_table->record[0]. Note that when record is located based on a primary 
@@ -9139,11 +9139,10 @@ int Rows_log_event::find_row(const Relay
     int restart_count= 0; // Number of times scanning has restarted from top
 
     /* We don't have a key: search the table using rnd_next() */
-    if ((error= table->file->ha_rnd_init(1)))
+    if ((error= table->file->ha_rnd_init_with_error(1)))
     {
       DBUG_PRINT("info",("error initializing table scan"
                          " (ha_rnd_init returns %d)",error));
-      table->file->print_error(error, MYF(0));
       goto err;
     }
 
@@ -9168,7 +9167,14 @@ int Rows_log_event::find_row(const Relay
 
       case HA_ERR_END_OF_FILE:
         if (++restart_count < 2)
-          table->file->ha_rnd_init(1);
+        {
+          int error2;
+          if ((error2= table->file->ha_rnd_init_with_error(1)))
+          {
+            error= error2;
+            goto err;
+          }
+        }
         break;
 
       default:

=== modified file 'sql/log_event_old.cc'
--- a/sql/log_event_old.cc	2010-06-01 19:52:20 +0000
+++ b/sql/log_event_old.cc	2010-07-16 22:41:44 +0000
@@ -816,7 +816,7 @@ static int find_and_fetch_row(TABLE *tab
     int error;
 
     /* We don't have a key: search the table using rnd_next() */
-    if ((error= table->file->ha_rnd_init(1)))
+    if ((error= table->file->ha_rnd_init_with_error(1)))
       return error;
 
     /* Continue until we find the right record or have made a full loop */
@@ -840,15 +840,19 @@ static int find_and_fetch_row(TABLE *tab
         goto restart_rnd_next;
 
       case HA_ERR_END_OF_FILE:
-  if (++restart_count < 2)
-    table->file->ha_rnd_init(1);
-  break;
+        if (++restart_count < 2)
+        {
+          int error2;
+          if ((error2= table->file->ha_rnd_init_with_error(1)))
+            DBUG_RETURN(error2);
+        }
+        break;
 
       default:
-  table->file->print_error(error, MYF(0));
+        table->file->print_error(error, MYF(0));
         DBUG_PRINT("info", ("Record not found"));
         table->file->ha_rnd_end();
-  DBUG_RETURN(error);
+        DBUG_RETURN(error);
       }
     }
     while (restart_count < 2 && record_compare(table));
@@ -2461,11 +2465,10 @@ int Old_rows_log_event::find_row(const R
     int restart_count= 0; // Number of times scanning has restarted from top
 
     /* We don't have a key: search the table using rnd_next() */
-    if ((error= table->file->ha_rnd_init(1)))
+    if ((error= table->file->ha_rnd_init_with_error(1)))
     {
       DBUG_PRINT("info",("error initializing table scan"
                          " (ha_rnd_init returns %d)",error));
-      table->file->print_error(error, MYF(0));
       DBUG_RETURN(error);
     }
 
@@ -2485,7 +2488,11 @@ int Old_rows_log_event::find_row(const R
 
       case HA_ERR_END_OF_FILE:
         if (++restart_count < 2)
-          table->file->ha_rnd_init(1);
+        {
+          int error2;
+          if ((error2= table->file->ha_rnd_init_with_error(1)))
+            DBUG_RETURN(error2);
+        }
         break;
 
       default:

=== modified file 'sql/mysql_priv.h'
--- a/sql/mysql_priv.h	2010-06-16 17:01:22 +0000
+++ b/sql/mysql_priv.h	2010-07-16 22:41:44 +0000
@@ -2303,7 +2303,7 @@ longlong get_datetime_value(THD *thd, It
 
 int test_if_number(char *str,int *res,bool allow_wildcards);
 void change_byte(uchar *,uint,char,char);
-void init_read_record(READ_RECORD *info, THD *thd, TABLE *reg_form,
+bool init_read_record(READ_RECORD *info, THD *thd, TABLE *reg_form,
 		      SQL_SELECT *select, int use_record_cache, 
                       bool print_errors, bool disable_rr_cache);
 void init_read_record_idx(READ_RECORD *info, THD *thd, TABLE *table, 

=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc	2010-06-05 14:53:36 +0000
+++ b/sql/opt_range.cc	2010-07-16 22:41:44 +0000
@@ -1431,7 +1431,7 @@ int QUICK_ROR_INTERSECT_SELECT::init_ror
     quick->record= head->record[0];
   }
 
-  if (need_to_fetch_row && head->file->ha_rnd_init(1))
+  if (need_to_fetch_row && head->file->ha_rnd_init_with_error(1))
   {
     DBUG_PRINT("error", ("ROR index_merge rnd_init call failed"));
     DBUG_RETURN(1);
@@ -1602,7 +1602,7 @@ int QUICK_ROR_UNION_SELECT::reset()
     queue_insert(&queue, (uchar*)quick);
   }
 
-  if (head->file->ha_rnd_init(1))
+  if (head->file->ha_rnd_init_with_error(1))
   {
     DBUG_PRINT("error", ("ROR index_merge rnd_init call failed"));
     DBUG_RETURN(1);
@@ -8199,7 +8199,8 @@ int QUICK_INDEX_MERGE_SELECT::read_keys_
     index_merge currently doesn't support "using index" at all
   */
   head->disable_keyread();
-  init_read_record(&read_record, thd, head, (SQL_SELECT*) 0, 1 , 1, TRUE);
+  if (init_read_record(&read_record, thd, head, (SQL_SELECT*) 0, 1 , 1, TRUE))
+    result= 1;
   DBUG_RETURN(result);
 
 err:

=== modified file 'sql/records.cc'
--- a/sql/records.cc	2010-06-01 19:52:20 +0000
+++ b/sql/records.cc	2010-07-16 22:41:44 +0000
@@ -157,7 +157,8 @@ void init_read_record_idx(READ_RECORD *i
     This is the most basic access method of a table using rnd_init,
     rnd_next and rnd_end. No indexes are used.
 */
-void init_read_record(READ_RECORD *info,THD *thd, TABLE *table,
+
+bool init_read_record(READ_RECORD *info,THD *thd, TABLE *table,
 		      SQL_SELECT *select,
 		      int use_record_cache, bool print_error, 
                       bool disable_rr_cache)
@@ -205,7 +206,8 @@ void init_read_record(READ_RECORD *info,
     reinit_io_cache(info->io_cache,READ_CACHE,0L,0,0);
     info->ref_pos=table->file->ref;
     if (!table->file->inited)
-      table->file->ha_rnd_init(0);
+      if (table->file->ha_rnd_init_with_error(0))
+        DBUG_RETURN(1);
 
     /*
       table->sort.addon_field is checked because if we use addon fields,
@@ -242,7 +244,8 @@ void init_read_record(READ_RECORD *info,
   else if (table->sort.record_pointers)
   {
     DBUG_PRINT("info",("using record_pointers"));
-    table->file->ha_rnd_init(0);
+    if (table->file->ha_rnd_init_with_error(0))
+      DBUG_RETURN(1);
     info->cache_pos=table->sort.record_pointers;
     info->cache_end=info->cache_pos+ 
                     table->sort.found_records*info->ref_length;
@@ -253,7 +256,8 @@ void init_read_record(READ_RECORD *info,
   {
     DBUG_PRINT("info",("using rr_sequential"));
     info->read_record=rr_sequential;
-    table->file->ha_rnd_init(1);
+    if (table->file->ha_rnd_init_with_error(1))
+      DBUG_RETURN(1);
     /* We can use record cache if we don't update dynamic length tables */
     if (!table->no_cache &&
 	(use_record_cache > 0 ||
@@ -271,7 +275,7 @@ void init_read_record(READ_RECORD *info,
       !table->file->pushed_cond)
     table->file->cond_push(select->cond);
 
-  DBUG_VOID_RETURN;
+  DBUG_RETURN(0);
 } /* init_read_record */
 
 

=== modified file 'sql/sql_acl.cc'
--- a/sql/sql_acl.cc	2010-06-02 15:53:12 +0000
+++ b/sql/sql_acl.cc	2010-07-16 22:41:44 +0000
@@ -477,8 +477,10 @@ static my_bool acl_load(THD *thd, TABLE_
   acl_cache->clear(1);				// Clear locked hostname cache
 
   init_sql_alloc(&mem, ACL_ALLOC_BLOCK_SIZE, 0);
-  init_read_record(&read_record_info,thd,table= tables[0].table,NULL,1,0, 
-                   FALSE);
+  if (init_read_record(&read_record_info,thd,table= tables[0].table,NULL,1,0, 
+                       FALSE))
+    goto end;
+
   table->use_all_columns();
   VOID(my_init_dynamic_array(&acl_hosts,sizeof(ACL_HOST),20,50));
   while (!(read_record_info.read_record(&read_record_info)))
@@ -527,7 +529,10 @@ static my_bool acl_load(THD *thd, TABLE_
   end_read_record(&read_record_info);
   freeze_size(&acl_hosts);
 
-  init_read_record(&read_record_info,thd,table=tables[1].table,NULL,1,0,FALSE);
+  if (init_read_record(&read_record_info,thd,table=tables[1].table,NULL,1,0,
+                       FALSE))
+    goto end;
+
   table->use_all_columns();
   VOID(my_init_dynamic_array(&acl_users,sizeof(ACL_USER),50,100));
   password_length= table->field[2]->field_length /
@@ -748,7 +753,10 @@ static my_bool acl_load(THD *thd, TABLE_
   end_read_record(&read_record_info);
   freeze_size(&acl_users);
 
-  init_read_record(&read_record_info,thd,table=tables[2].table,NULL,1,0,FALSE);
+  if (init_read_record(&read_record_info,thd,table=tables[2].table,NULL,1,0,
+                       FALSE))
+    goto end;
+
   table->use_all_columns();
   VOID(my_init_dynamic_array(&acl_dbs,sizeof(ACL_DB),50,100));
   while (!(read_record_info.read_record(&read_record_info)))

=== modified file 'sql/sql_cursor.cc'
--- a/sql/sql_cursor.cc	2009-10-19 17:14:48 +0000
+++ b/sql/sql_cursor.cc	2010-07-16 22:41:44 +0000
@@ -608,7 +608,7 @@ int Materialized_cursor::open(JOIN *join
   thd->set_n_backup_active_arena(this, &backup_arena);
   /* Create a list of fields and start sequential scan */
   rc= result->prepare(item_list, &fake_unit);
-  if (!rc && !(rc= table->file->ha_rnd_init(TRUE)))
+  if (!rc && !(rc= table->file->ha_rnd_init_with_error(TRUE)))
     is_rnd_inited= 1;
 
   thd->restore_active_arena(this, &backup_arena);

=== modified file 'sql/sql_delete.cc'
--- a/sql/sql_delete.cc	2010-07-03 03:24:39 +0000
+++ b/sql/sql_delete.cc	2010-07-16 22:41:44 +0000
@@ -266,7 +266,14 @@ bool mysql_delete(THD *thd, TABLE_LIST *
     DBUG_RETURN(TRUE);
   }
   if (usable_index==MAX_KEY)
-    init_read_record(&info, thd, table, select, 1, 1, FALSE);
+  {
+    if (init_read_record(&info, thd, table, select, 1, 1, FALSE))
+    {
+      delete select;
+      free_underlaid_joins(thd, select_lex);
+      DBUG_RETURN(TRUE);
+    }
+  }
   else
     init_read_record_idx(&info, thd, table, 1, usable_index);
 
@@ -944,7 +951,10 @@ int multi_delete::do_table_deletes(TABLE
   READ_RECORD info;
   ha_rows last_deleted= deleted;
   DBUG_ENTER("do_deletes_for_table");
-  init_read_record(&info, thd, table, NULL, 0, 1, FALSE);
+
+  if (init_read_record(&info, thd, table, NULL, 0, 1, FALSE))
+    DBUG_RETURN(1);
+
   /*
     Ignore any rows not found in reference tables as they may already have
     been deleted by foreign key handling

=== modified file 'sql/sql_help.cc'
--- a/sql/sql_help.cc	2009-10-19 17:14:48 +0000
+++ b/sql/sql_help.cc	2010-07-16 22:41:44 +0000
@@ -182,11 +182,14 @@ int search_topics(THD *thd, TABLE *topic
 		  SQL_SELECT *select, List<String> *names,
 		  String *name, String *description, String *example)
 {
-  DBUG_ENTER("search_topics");
   int count= 0;
-
   READ_RECORD read_record_info;
-  init_read_record(&read_record_info, thd, topics, select, 1, 0, FALSE);
+  DBUG_ENTER("search_topics");
+
+  /* Should never happen. As this is part of help, we can ignore this */
+  if (init_read_record(&read_record_info, thd, topics, select, 1, 0, FALSE))
+    DBUG_RETURN(0);
+
   while (!read_record_info.read_record(&read_record_info))
   {
     if (!select->cond->val_int())		// Doesn't match like
@@ -222,11 +225,13 @@ int search_topics(THD *thd, TABLE *topic
 int search_keyword(THD *thd, TABLE *keywords, struct st_find_field *find_fields,
                    SQL_SELECT *select, int *key_id)
 {
-  DBUG_ENTER("search_keyword");
   int count= 0;
-
   READ_RECORD read_record_info;
-  init_read_record(&read_record_info, thd, keywords, select, 1, 0, FALSE);
+  DBUG_ENTER("search_keyword");
+  /* Should never happen. As this is part of help, we can ignore this */
+  if (init_read_record(&read_record_info, thd, keywords, select, 1, 0, FALSE))
+    DBUG_RETURN(0);
+
   while (!read_record_info.read_record(&read_record_info) && count<2)
   {
     if (!select->cond->val_int())		// Dosn't match like
@@ -347,10 +352,11 @@ int search_categories(THD *thd, TABLE *c
   Field *pcat_id= find_fields[help_category_help_category_id].field;
   int count= 0;
   READ_RECORD read_record_info;
-
   DBUG_ENTER("search_categories");
 
-  init_read_record(&read_record_info, thd, categories, select,1,0,FALSE);
+  /* Should never happen. As this is part of help, we can ignore this */
+  if (init_read_record(&read_record_info, thd, categories, select,1,0,FALSE))
+    DBUG_RETURN(0);
   while (!read_record_info.read_record(&read_record_info))
   {
     if (select && !select->cond->val_int())
@@ -381,10 +387,13 @@ int search_categories(THD *thd, TABLE *c
 void get_all_items_for_category(THD *thd, TABLE *items, Field *pfname,
 				SQL_SELECT *select, List<String> *res)
 {
+  READ_RECORD read_record_info;
   DBUG_ENTER("get_all_items_for_category");
 
-  READ_RECORD read_record_info;
-  init_read_record(&read_record_info, thd, items, select,1,0,FALSE);
+  /* Should never happen. As this is part of help, we can ignore this */
+  if (init_read_record(&read_record_info, thd, items, select,1,0,FALSE))
+    DBUG_VOID_RETURN;
+
   while (!read_record_info.read_record(&read_record_info))
   {
     if (!select->cond->val_int())

=== modified file 'sql/sql_plugin.cc'
--- a/sql/sql_plugin.cc	2010-06-16 17:01:22 +0000
+++ b/sql/sql_plugin.cc	2010-07-16 22:41:44 +0000
@@ -1621,7 +1621,12 @@ static void plugin_load(MEM_ROOT *tmp_ro
     goto end;
   }
   table= tables.table;
-  init_read_record(&read_record_info, new_thd, table, NULL, 1, 0, FALSE);
+  if (init_read_record(&read_record_info, new_thd, table, NULL, 1, 0, FALSE))
+  {
+    sql_print_error("Could not initialize init_read_record; Plugins not "
+                    "loaded");
+    goto end;
+  }
   table->use_all_columns();
   /*
     there're no other threads running yet, so we don't need a mutex.

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2010-06-05 14:53:36 +0000
+++ b/sql/sql_select.cc	2010-07-16 22:41:44 +0000
@@ -11069,7 +11069,8 @@ create_internal_tmp_table_from_heap2(THD
   if (table->file->indexes_are_disabled())
     new_table.file->ha_disable_indexes(HA_KEY_SWITCH_ALL);
   table->file->ha_index_or_rnd_end();
-  table->file->ha_rnd_init(1);
+  if (table->file->ha_rnd_init_with_error(1))
+    DBUG_RETURN(1);
   if (table->no_rows)
   {
     new_table.file->extra(HA_EXTRA_NO_ROWS);
@@ -12322,7 +12323,7 @@ int rr_sequential(READ_RECORD *info);
 int init_read_record_seq(JOIN_TAB *tab)
 {
   tab->read_record.read_record= rr_sequential;
-  if (tab->read_record.file->ha_rnd_init(1))
+  if (tab->read_record.file->ha_rnd_init_with_error(1))
     return 1;
   return (*tab->read_record.read_record)(&tab->read_record);
 }
@@ -12342,8 +12343,9 @@ join_init_read_record(JOIN_TAB *tab)
 {
   if (tab->select && tab->select->quick && tab->select->quick->reset())
     return 1;
-  init_read_record(&tab->read_record, tab->join->thd, tab->table,
-		   tab->select,1,1, FALSE);
+  if (init_read_record(&tab->read_record, tab->join->thd, tab->table,
+                       tab->select,1,1, FALSE))
+    return 1;
   return (*tab->read_record.read_record)(&tab->read_record);
 }
 
@@ -14264,7 +14266,9 @@ static int remove_dup_with_compare(THD *
   org_record=(char*) (record=table->record[0])+offset;
   new_record=(char*) table->record[1]+offset;
 
-  file->ha_rnd_init(1);
+  if (file->ha_rnd_init_with_error(1))
+    DBUG_RETURN(1);
+
   error= file->ha_rnd_next(record);
   for (;;)
   {
@@ -14393,7 +14397,9 @@ static int remove_dup_with_hash_index(TH
     DBUG_RETURN(1);
   }
 
-  file->ha_rnd_init(1);
+  if ((error= file->ha_rnd_init(1)))
+    goto err;
+
   key_pos=key_buffer;
   for (;;)
   {

=== modified file 'sql/sql_servers.cc'
--- a/sql/sql_servers.cc	2010-03-15 11:51:23 +0000
+++ b/sql/sql_servers.cc	2010-07-16 22:41:44 +0000
@@ -182,8 +182,9 @@ static bool servers_load(THD *thd, TABLE
   free_root(&mem, MYF(0));
   init_alloc_root(&mem, ACL_ALLOC_BLOCK_SIZE, 0);
 
-  init_read_record(&read_record_info,thd,table=tables[0].table,NULL,1,0, 
-                   FALSE);
+  if (init_read_record(&read_record_info,thd,table=tables[0].table,NULL,1,0, 
+                       FALSE))
+    DBUG_RETURN(1);
   while (!(read_record_info.read_record(&read_record_info)))
   {
     /* return_val is already TRUE, so no need to set */

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2010-06-05 14:53:36 +0000
+++ b/sql/sql_table.cc	2010-07-16 22:41:44 +0000
@@ -7877,7 +7877,8 @@ copy_data_between_tables(TABLE *from,TAB
   /* Tell handler that we have values for all columns in the to table */
   to->use_all_columns();
   to->mark_virtual_columns_for_write();
-  init_read_record(&info, thd, from, (SQL_SELECT *) 0, 1, 1, FALSE);
+  if (init_read_record(&info, thd, from, (SQL_SELECT *) 0, 1, 1, FALSE))
+    goto err;
   errpos= 4;
   if (ignore)
     to->file->extra(HA_EXTRA_IGNORE_DUP_KEY);

=== modified file 'sql/sql_udf.cc'
--- a/sql/sql_udf.cc	2010-03-15 11:51:23 +0000
+++ b/sql/sql_udf.cc	2010-07-16 22:41:44 +0000
@@ -152,7 +152,13 @@ void udf_init()
   }
 
   table= tables.table;
-  init_read_record(&read_record_info, new_thd, table, NULL,1,0,FALSE);
+  if (init_read_record(&read_record_info, new_thd, table, NULL,1,0,FALSE))
+  {
+    sql_print_error("Could not initialize init_read_record; udf's not "
+                    "loaded");
+    goto end;
+  }
+
   table->use_all_columns();
   while (!(error= read_record_info.read_record(&read_record_info)))
   {

=== modified file 'sql/sql_update.cc'
--- a/sql/sql_update.cc	2010-07-03 03:24:39 +0000
+++ b/sql/sql_update.cc	2010-07-16 22:41:44 +0000
@@ -459,7 +459,10 @@ int mysql_update(THD *thd,
       */
 
       if (used_index == MAX_KEY || (select && select->quick))
-        init_read_record(&info, thd, table, select, 0, 1, FALSE);
+      {
+        if (init_read_record(&info, thd, table, select, 0, 1, FALSE))
+          goto err;
+      }
       else
         init_read_record_idx(&info, thd, table, 1, used_index);
 
@@ -527,7 +530,8 @@ int mysql_update(THD *thd,
   if (select && select->quick && select->quick->reset())
     goto err;
   table->file->try_semi_consistent_read(1);
-  init_read_record(&info, thd, table, select, 0, 1, FALSE);
+  if (init_read_record(&info, thd, table, select, 0, 1, FALSE))
+    goto err;
 
   updated= found= 0;
   /*
@@ -1954,7 +1958,7 @@ int multi_update::do_updates()
   TABLE_LIST *cur_table;
   int local_error= 0;
   ha_rows org_updated;
-  TABLE *table, *tmp_table;
+  TABLE *table, *tmp_table, *err_table;
   List_iterator_fast<TABLE> check_opt_it(unupdated_check_opt_tables);
   DBUG_ENTER("multi_update::do_updates");
 
@@ -1972,14 +1976,21 @@ int multi_update::do_updates()
     org_updated= updated;
     tmp_table= tmp_tables[cur_table->shared];
     tmp_table->file->extra(HA_EXTRA_CACHE);	// Change to read cache
-    (void) table->file->ha_rnd_init(0);
+    if ((local_error= table->file->ha_rnd_init(0)))
+    {
+      err_table= table;
+      goto err;
+    }
     table->file->extra(HA_EXTRA_NO_CACHE);
 
     check_opt_it.rewind();
     while(TABLE *tbl= check_opt_it++)
     {
-      if (tbl->file->ha_rnd_init(1))
+      if ((local_error= tbl->file->ha_rnd_init(1)))
+      {
+        err_table= tbl;
         goto err;
+      }
       tbl->file->extra(HA_EXTRA_CACHE);
     }
 
@@ -1997,8 +2008,11 @@ int multi_update::do_updates()
     }
     copy_field_end=copy_field_ptr;
 
-    if ((local_error = tmp_table->file->ha_rnd_init(1)))
+    if ((local_error= tmp_table->file->ha_rnd_init(1)))
+    {
+      err_table= tmp_table;
       goto err;
+    }
 
     can_compare_record= (!(table->file->ha_table_flags() &
                            HA_PARTIAL_COLUMN_READ) ||
@@ -2008,13 +2022,17 @@ int multi_update::do_updates()
     for (;;)
     {
       if (thd->killed && trans_safe)
-	goto err;
+      {
+        thd->fatal_error();
+	goto err2;
+      }
       if ((local_error= tmp_table->file->ha_rnd_next(tmp_table->record[0])))
       {
 	if (local_error == HA_ERR_END_OF_FILE)
 	  break;
 	if (local_error == HA_ERR_RECORD_DELETED)
 	  continue;				// May happen on dup key
+        err_table= tmp_table;
 	goto err;
       }
 
@@ -2027,7 +2045,10 @@ int multi_update::do_updates()
         if ((local_error=
              tbl->file->ha_rnd_pos(tbl->record[0],
                                    (uchar*) tmp_table->field[field_num]->ptr)))
+        {
+          err_table= tbl;
           goto err;
+        }
         field_num++;
       } while ((tbl= check_opt_it++));
 
@@ -2054,7 +2075,10 @@ int multi_update::do_updates()
           if (error == VIEW_CHECK_SKIP)
             continue;
           else if (error == VIEW_CHECK_ERROR)
-            goto err;
+          {
+            thd->fatal_error();
+            goto err2;
+          }
         }
 	if ((local_error=table->file->ha_update_row(table->record[1],
 						    table->record[0])) &&
@@ -2062,7 +2086,10 @@ int multi_update::do_updates()
 	{
 	  if (!ignore ||
               table->file->is_fatal_error(local_error, HA_CHECK_DUP_KEY))
+          {
+            err_table= table;
 	    goto err;
+          }
 	}
         if (local_error != HA_ERR_RECORD_IS_THE_SAME)
           updated++;

=== modified file 'storage/example/ha_example.cc'
--- a/storage/example/ha_example.cc	2010-04-30 20:09:27 +0000
+++ b/storage/example/ha_example.cc	2010-07-16 22:41:44 +0000
@@ -588,7 +588,7 @@ int ha_example::index_last(uchar *buf)
 int ha_example::rnd_init(bool scan)
 {
   DBUG_ENTER("ha_example::rnd_init");
-  DBUG_RETURN(HA_ERR_WRONG_COMMAND);
+  DBUG_RETURN(0);
 }
 
 int ha_example::rnd_end()

=== modified file 'storage/ibmdb2i/ha_ibmdb2i.cc'
--- a/storage/ibmdb2i/ha_ibmdb2i.cc	2010-04-01 14:34:51 +0000
+++ b/storage/ibmdb2i/ha_ibmdb2i.cc	2010-07-16 22:41:44 +0000
@@ -1158,9 +1158,7 @@ int ha_ibmdb2i::rnd_init(bool scan)
   
   rrnAssocHandle= 0;
 
-  DBUG_RETURN(0); // MySQL sometimes does not check the return code, causing 
-                  // an assert in ha_rnd_end later on if we return a non-zero
-                  // value here. 
+  DBUG_RETURN(0);
 }
 
 int ha_ibmdb2i::rnd_end()



More information about the commits mailing list