~ubuntu-branches/ubuntu/natty/mysql-5.1/natty-proposed

« back to all changes in this revision

Viewing changes to sql/opt_sum.cc

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 08:30:45 UTC
  • mfrom: (1.4.1)
  • Revision ID: package-import@ubuntu.com-20120222083045-2rd53r4bnyx7qus4
Tags: 5.1.61-0ubuntu0.11.04.1
* SECURITY UPDATE: Update to 5.1.61 to fix multiple security issues
  (LP: #937869)
  - http://www.oracle.com/technetwork/topics/security/cpujan2012-366304.html
  - CVE-2011-2262
  - CVE-2012-0075
  - CVE-2012-0112
  - CVE-2012-0113
  - CVE-2012-0114
  - CVE-2012-0115
  - CVE-2012-0116
  - CVE-2012-0117
  - CVE-2012-0118
  - CVE-2012-0119
  - CVE-2012-0120
  - CVE-2012-0484
  - CVE-2012-0485
  - CVE-2012-0486
  - CVE-2012-0487
  - CVE-2012-0488
  - CVE-2012-0489
  - CVE-2012-0490
  - CVE-2012-0491
  - CVE-2012-0492
  - CVE-2012-0493
  - CVE-2012-0494
  - CVE-2012-0495
  - CVE-2012-0496

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved.
 
1
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
2
2
 
3
3
   This program is free software; you can redistribute it and/or modify
4
4
   it under the terms of the GNU General Public License as published by
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 
15
*/
15
16
 
16
17
 
17
18
/**
211
212
/**
212
213
  Substitutes constants for some COUNT(), MIN() and MAX() functions.
213
214
 
 
215
  @param thd                   thread handler
214
216
  @param tables                list of leaves of join table tree
215
217
  @param all_fields            All fields to be returned
216
218
  @param conds                 WHERE clause
228
230
    HA_ERR_KEY_NOT_FOUND on impossible conditions
229
231
  @retval
230
232
    HA_ERR_... if a deadlock or a lock wait timeout happens, for example
 
233
  @retval
 
234
    ER_...     e.g. ER_SUBQUERY_NO_1_ROW
231
235
*/
232
236
 
233
 
int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
 
237
int opt_sum_query(THD *thd,
 
238
                  TABLE_LIST *tables, List<Item> &all_fields, COND *conds)
234
239
{
235
240
  List_iterator_fast<Item> it(all_fields);
236
241
  int const_result= 1;
242
247
  Item *item;
243
248
  int error;
244
249
 
 
250
  DBUG_ENTER("opt_sum_query");
 
251
 
245
252
  if (conds)
246
253
    where_tables= conds->used_tables();
247
254
 
269
276
          WHERE t2.field IS NULL;
270
277
      */
271
278
      if (tl->table->map & where_tables)
272
 
        return 0;
 
279
        DBUG_RETURN(0);
273
280
    }
274
281
    else
275
282
      used_tables|= tl->table->map;
297
304
      {
298
305
        tl->table->file->print_error(error, MYF(0));
299
306
        tl->table->in_use->fatal_error();
300
 
        return error;
 
307
        DBUG_RETURN(error);
301
308
      }
302
309
      count*= tl->table->file->stats.records;
303
310
    }
390
397
          if (error)
391
398
          {
392
399
            if (error == HA_ERR_KEY_NOT_FOUND || error == HA_ERR_END_OF_FILE)
393
 
              return HA_ERR_KEY_NOT_FOUND;            // No rows matching WHERE
 
400
              DBUG_RETURN(HA_ERR_KEY_NOT_FOUND); // No rows matching WHERE
394
401
            /* HA_ERR_LOCK_DEADLOCK or some other error */
395
402
            table->file->print_error(error, MYF(0));
396
 
            return(error);
 
403
            DBUG_RETURN(error);
397
404
          }
398
405
          removed_tables|= table->map;
399
406
        }
437
444
        const_result= 0;
438
445
    }
439
446
  }
 
447
 
 
448
  if (thd->is_error())
 
449
    DBUG_RETURN(thd->main_da.sql_errno());
 
450
 
440
451
  /*
441
452
    If we have a where clause, we can only ignore searching in the
442
453
    tables if MIN/MAX optimisation replaced all used tables
446
457
  */
447
458
  if (removed_tables && used_tables != removed_tables)
448
459
    const_result= 0;                            // We didn't remove all tables
449
 
  return const_result;
 
460
  DBUG_RETURN(const_result);
450
461
}
451
462
 
452
463
 
732
743
 
733
744
    if (is_null || (is_null_safe_eq && args[1]->is_null()))
734
745
    {
 
746
      /*
 
747
        If we have a non-nullable index, we cannot use it,
 
748
        since set_null will be ignored, and we will compare uninitialized data.
 
749
      */
 
750
      if (!part->field->real_maybe_null())
 
751
        DBUG_RETURN(false);
735
752
      part->field->set_null();
736
753
      *key_ptr= (uchar) 1;
737
754
    }
802
819
  @param[out]    prefix_len  Length of prefix for the search range
803
820
 
804
821
  @note
805
 
    This function may set table->key_read to 1, which must be reset after
806
 
    index is used! (This can only happen when function returns 1)
 
822
    This function may set field->table->key_read to true,
 
823
    which must be reset after index is used!
 
824
    (This can only happen when function returns 1)
807
825
 
808
826
  @retval
809
827
    0   Index can not be used to optimize MIN(field)/MAX(field)
818
836
                                uint *range_fl, uint *prefix_len)
819
837
{
820
838
  if (!(field->flags & PART_KEY_FLAG))
821
 
    return 0;                                        // Not key field
 
839
    return false;                               // Not key field
 
840
 
 
841
  DBUG_ENTER("find_key_for_maxmin");
822
842
 
823
843
  TABLE *table= field->table;
824
844
  uint idx= 0;
843
863
         part++, jdx++, key_part_to_use= (key_part_to_use << 1) | 1)
844
864
    {
845
865
      if (!(table->file->index_flags(idx, jdx, 0) & HA_READ_ORDER))
846
 
        return 0;
 
866
        DBUG_RETURN(false);
847
867
 
848
868
      /* Check whether the index component is partial */
849
869
      Field *part_field= table->field[part->fieldnr-1];
892
912
          */
893
913
          if (field->part_of_key.is_set(idx))
894
914
            table->set_keyread(TRUE);
895
 
          return 1;
 
915
          DBUG_RETURN(true);
896
916
        }
897
917
      }
898
918
    }
899
919
  }
900
 
  return 0;
 
920
  DBUG_RETURN(false);
901
921
}
902
922
 
903
923