~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/join.cc

Merged with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
#include "drizzled/optimizer/key_use.h"
51
51
#include "drizzled/optimizer/range.h"
52
52
#include "drizzled/optimizer/sum.h"
 
53
#include "drizzled/optimizer/explain_plan.h"
53
54
#include "drizzled/records.h"
 
55
#include "drizzled/probes.h"
54
56
#include "mysys/my_bit.h"
55
57
 
56
58
#include <algorithm>
625
627
  {
626
628
    conds=new Item_int((int64_t) 0,1);  // Always false
627
629
  }
 
630
 
628
631
  if (make_join_select(this, select, conds))
629
632
  {
630
633
    zero_result_cause=
832
835
  if (setup_subquery_materialization())
833
836
    return 1;
834
837
 
 
838
  /* Cache constant expressions in WHERE, HAVING, ON clauses. */
 
839
  cache_const_exprs();
 
840
 
835
841
  /*
836
842
    is this simple IN subquery?
837
843
  */
1200
1206
  {                                           
1201
1207
    /* Only test of functions */
1202
1208
    if (select_options & SELECT_DESCRIBE)
1203
 
      select_describe(this, false, false, false, (zero_result_cause?zero_result_cause:"No tables used"));
 
1209
    {
 
1210
      optimizer::ExplainPlan planner(this, 
 
1211
                                     false,
 
1212
                                     false,
 
1213
                                     false,
 
1214
                                     (zero_result_cause ? zero_result_cause : "No tables used"));
 
1215
      planner.printPlan();
 
1216
    }
1204
1217
    else
1205
1218
    {
1206
1219
      result->send_fields(*columns_list);
1273
1286
      order= 0;
1274
1287
    }
1275
1288
    having= tmp_having;
1276
 
    select_describe(this, need_tmp, order != 0 && !skip_sort_order,  select_distinct, !tables ? "No tables used" : NULL);
 
1289
    optimizer::ExplainPlan planner(this,
 
1290
                                   need_tmp,
 
1291
                                   order != 0 && ! skip_sort_order,
 
1292
                                   select_distinct,
 
1293
                                   ! tables ? "No tables used" : NULL);
 
1294
    planner.printPlan();
1277
1295
    return;
1278
1296
  }
1279
1297
 
2383
2401
}
2384
2402
 
2385
2403
/**
 
2404
  Cache constant expressions in WHERE, HAVING, ON conditions.
 
2405
*/
 
2406
 
 
2407
void JOIN::cache_const_exprs()
 
2408
{
 
2409
  bool cache_flag= false;
 
2410
  bool *analyzer_arg= &cache_flag;
 
2411
 
 
2412
  /* No need in cache if all tables are constant. */
 
2413
  if (const_tables == tables)
 
2414
    return;
 
2415
 
 
2416
  if (conds)
 
2417
    conds->compile(&Item::cache_const_expr_analyzer, (unsigned char **)&analyzer_arg,
 
2418
                  &Item::cache_const_expr_transformer, (unsigned char *)&cache_flag);
 
2419
  cache_flag= false;
 
2420
  if (having)
 
2421
    having->compile(&Item::cache_const_expr_analyzer, (unsigned char **)&analyzer_arg,
 
2422
                    &Item::cache_const_expr_transformer, (unsigned char *)&cache_flag);
 
2423
 
 
2424
  for (JoinTable *tab= join_tab + const_tables; tab < join_tab + tables ; tab++)
 
2425
  {
 
2426
    if (*tab->on_expr_ref)
 
2427
    {
 
2428
      cache_flag= false;
 
2429
      (*tab->on_expr_ref)->compile(&Item::cache_const_expr_analyzer,
 
2430
                                 (unsigned char **)&analyzer_arg,
 
2431
                                 &Item::cache_const_expr_transformer,
 
2432
                                 (unsigned char *)&cache_flag);
 
2433
    }
 
2434
  }
 
2435
}
 
2436
 
 
2437
/**
2386
2438
  @brief
2387
2439
  
2388
2440
  Process one record of the nested loop join.
5128
5180
{
5129
5181
  if (select_options & SELECT_DESCRIBE)
5130
5182
  {
5131
 
    select_describe(join, false, false, false, info);
5132
 
    return(0);
 
5183
    optimizer::ExplainPlan planner(join,
 
5184
                                   false,
 
5185
                                   false,
 
5186
                                   false,
 
5187
                                   info);
 
5188
    planner.printPlan();
 
5189
    return 0;
5133
5190
  }
5134
5191
 
5135
5192
  join->join_free();
5932
5989
  if (join->const_tables != join->tables)
5933
5990
  {
5934
5991
    optimize_keyuse(join, keyuse_array);
5935
 
    if (choose_plan(join, all_table_map & ~join->const_table_map))
5936
 
      return(true);
 
5992
    DRIZZLE_QUERY_OPT_CHOOSE_PLAN_START(join->session->query, join->session->thread_id);
 
5993
    bool res= choose_plan(join, all_table_map & ~join->const_table_map);
 
5994
    DRIZZLE_QUERY_OPT_CHOOSE_PLAN_DONE(res ? 1 : 0);
 
5995
    if (res)
 
5996
      return true;
5937
5997
  }
5938
5998
  else
5939
5999
  {