~ubuntu-branches/ubuntu/hardy/mysql-dfsg-5.0/hardy-updates

« back to all changes in this revision

Viewing changes to sql/item_subselect.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2007-04-02 16:10:53 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20070402161053-zkil9hjq9k5p1uzv
Tags: 5.0.37-0ubuntu1
* New upstream bugfix release.
  - Fixes replication failure with auto-increment and on duplicate key
    update, a regression introduced into 5.0.24. (LP: #95821)
* debian/control: Set Ubuntu maintainer.
* debian/rules: Change comments from 'Debian etch' to 'Ubuntu 7.04'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
5
 
   the Free Software Foundation; either version 2 of the License, or
6
 
   (at your option) any later version.
 
5
   the Free Software Foundation; version 2 of the License.
7
6
 
8
7
   This program is distributed in the hope that it will be useful,
9
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
95
94
    return null_value;
96
95
  }
97
96
  bool fix_fields(THD *thd, Item **ref);
98
 
  virtual bool exec(bool full_scan);
 
97
  virtual bool exec();
99
98
  virtual void fix_length_and_dec();
100
99
  table_map used_tables() const;
101
100
  table_map not_null_tables() const { return 0; }
105
104
  Item *get_tmp_table_item(THD *thd);
106
105
  void update_used_tables();
107
106
  void print(String *str);
 
107
  virtual bool have_guarded_conds() { return FALSE; }
108
108
  bool change_engine(subselect_engine *eng)
109
109
  {
110
110
    old_engine= engine;
250
250
  bool transformed;
251
251
public:
252
252
  /* Used to trigger on/off conditions that were pushed down to subselect */
253
 
  bool enable_pushed_conds;
 
253
  bool *pushed_cond_guards;
 
254
 
 
255
  bool *get_cond_guard(int i)
 
256
  {
 
257
    return pushed_cond_guards ? pushed_cond_guards + i : NULL;
 
258
  }
 
259
  void set_cond_guard_var(int i, bool v) { pushed_cond_guards[i]= v; }
 
260
  bool have_guarded_conds() { return test(pushed_cond_guards); }
 
261
 
254
262
  Item_func_not_all *upper_item; // point on NOT/NOP before ALL/SOME subquery
255
263
 
256
264
  Item_in_subselect(Item * left_expr, st_select_lex *select_lex);
257
265
  Item_in_subselect()
258
266
    :Item_exists_subselect(), optimizer(0), abort_on_null(0), transformed(0),
259
 
     enable_pushed_conds(TRUE), upper_item(0)
 
267
     pushed_cond_guards(NULL), upper_item(0)
260
268
  {}
261
269
 
262
270
  subs_type substype() { return IN_SUBS; }
341
349
 
342
350
    SYNOPSIS
343
351
      exec()
344
 
        full_scan TRUE  - Pushed-down predicates are disabled, the engine
345
 
                          must disable made based on those predicates.
346
 
                  FALSE - Pushed-down predicates are in effect.
 
352
 
347
353
    DESCRIPTION
348
354
      Execute the engine. The result of execution is subquery value that is
349
355
      either captured by previously set up select_result-based 'sink' or
350
356
      stored somewhere by the exec() method itself.
351
357
 
352
 
      A required side effect: if full_scan==TRUE, subselect_engine->no_rows()
353
 
      should return correct result.
 
358
      A required side effect: If at least one pushed-down predicate is
 
359
      disabled, subselect_engine->no_rows() must return correct result after 
 
360
      the exec() call.
354
361
 
355
362
    RETURN
356
363
      0 - OK
357
 
      1 - Either an execution error, or the engine was be "changed", and
 
364
      1 - Either an execution error, or the engine was "changed", and the
358
365
          caller should call exec() again for the new engine.
359
366
  */
360
 
  virtual int exec(bool full_scan)= 0;
 
367
  virtual int exec()= 0;
361
368
  virtual uint cols()= 0; /* return number of columns in select */
362
369
  virtual uint8 uncacheable()= 0; /* query is uncacheable */
363
370
  enum Item_result type() { return res_type; }
364
371
  enum_field_types field_type() { return res_field_type; }
365
372
  virtual void exclude()= 0;
366
 
  bool may_be_null() { return maybe_null; };
 
373
  virtual bool may_be_null() { return maybe_null; };
367
374
  virtual table_map upper_select_const_tables()= 0;
368
375
  static table_map calc_const_tables(TABLE_LIST *);
369
376
  virtual void print(String *str)= 0;
392
399
  void cleanup();
393
400
  int prepare();
394
401
  void fix_length_and_dec(Item_cache** row);
395
 
  int exec(bool full_scan);
 
402
  int exec();
396
403
  uint cols();
397
404
  uint8 uncacheable();
398
405
  void exclude();
400
407
  void print (String *str);
401
408
  bool change_result(Item_subselect *si, select_subselect *result);
402
409
  bool no_tables();
 
410
  bool may_be_null();
403
411
  bool is_executed() const { return executed; }
404
412
  bool no_rows();
405
413
};
415
423
  void cleanup();
416
424
  int prepare();
417
425
  void fix_length_and_dec(Item_cache** row);
418
 
  int exec(bool full_scan);
 
426
  int exec();
419
427
  uint cols();
420
428
  uint8 uncacheable();
421
429
  void exclude();
429
437
 
430
438
 
431
439
struct st_join_table;
 
440
 
 
441
 
 
442
/*
 
443
  A subquery execution engine that evaluates the subquery by doing one index
 
444
  lookup in a unique index.
 
445
 
 
446
  This engine is used to resolve subqueries in forms
 
447
  
 
448
    outer_expr IN (SELECT tbl.unique_key FROM tbl WHERE subq_where) 
 
449
    
 
450
  or, tuple-based:
 
451
  
 
452
    (oe1, .. oeN) IN (SELECT uniq_key_part1, ... uniq_key_partK
 
453
                      FROM tbl WHERE subqwhere) 
 
454
  
 
455
  i.e. the subquery is a single table SELECT without GROUP BY, aggregate
 
456
  functions, etc.
 
457
*/
 
458
 
432
459
class subselect_uniquesubquery_engine: public subselect_engine
433
460
{
434
461
protected:
435
462
  st_join_table *tab;
436
 
  Item *cond;
 
463
  Item *cond; /* The WHERE condition of subselect */
437
464
  /* 
438
465
    TRUE<=> last execution produced empty set. Valid only when left
439
466
    expression is NULL.
453
480
  void cleanup();
454
481
  int prepare();
455
482
  void fix_length_and_dec(Item_cache** row);
456
 
  int exec(bool full_scan);
 
483
  int exec();
457
484
  uint cols() { return 1; }
458
485
  uint8 uncacheable() { return UNCACHEABLE_DEPENDENT; }
459
486
  void exclude();
471
498
{
472
499
  /* FALSE for 'ref', TRUE for 'ref-or-null'. */
473
500
  bool check_null;
 
501
  /* 
 
502
    The "having" clause. This clause (further reffered to as "artificial
 
503
    having") was inserted by subquery transformation code. It contains 
 
504
    Item(s) that have a side-effect: they record whether the subquery has 
 
505
    produced a row with NULL certain components. We need to use it for cases
 
506
    like
 
507
      (oe1, oe2) IN (SELECT t.key, t.no_key FROM t1)
 
508
    where we do index lookup on t.key=oe1 but need also to check if there
 
509
    was a row such that t.no_key IS NULL.
 
510
    
 
511
    NOTE: This is currently here and not in the uniquesubquery_engine. Ideally
 
512
    it should have been in uniquesubquery_engine in order to allow execution of
 
513
    subqueries like
 
514
    
 
515
      (oe1, oe2) IN (SELECT primary_key, non_key_maybe_null_field FROM tbl)
 
516
 
 
517
    We could use uniquesubquery_engine for the first component and let
 
518
    Item_is_not_null_test( non_key_maybe_null_field) to handle the second.
 
519
 
 
520
    However, subqueries like the above are currently not handled by index
 
521
    lookup-based subquery engines, the engine applicability check misses
 
522
    them: it doesn't switch the engine for case of artificial having and
 
523
    [eq_]ref access (only for artifical having + ref_or_null or no having).
 
524
    The above example subquery is handled as a full-blown SELECT with eq_ref
 
525
    access to one table.
 
526
 
 
527
    Due to this limitation, the "artificial having" currently needs to be 
 
528
    checked by only in indexsubquery_engine.
 
529
  */
 
530
  Item *having;
474
531
public:
475
532
 
476
533
  // constructor can assign THD because it will be called after JOIN::prepare
477
534
  subselect_indexsubquery_engine(THD *thd, st_join_table *tab_arg,
478
535
                                 Item_subselect *subs, Item *where,
479
 
                                 bool chk_null)
 
536
                                 Item *having_arg, bool chk_null)
480
537
    :subselect_uniquesubquery_engine(thd, tab_arg, subs, where),
481
 
     check_null(chk_null)
 
538
     check_null(chk_null),
 
539
     having(having_arg)
482
540
  {}
483
 
  int exec(bool full_scan);
 
541
  int exec();
484
542
  void print (String *str);
485
543
};
486
544