~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/join.cc

Merged Drizzle's Trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
495
495
    {           /* Impossible cond */
496
496
      zero_result_cause=  having_value == Item::COND_FALSE ?
497
497
                           "Impossible HAVING" : "Impossible WHERE";
498
 
      error= 0;
499
 
      return(0);
 
498
      goto setup_subq_exit;
500
499
    }
501
500
  }
502
501
 
515
514
      if (res == HA_ERR_KEY_NOT_FOUND)
516
515
      {
517
516
        zero_result_cause= "No matching min/max row";
518
 
        error=0;
519
 
        return(0);
 
517
        goto setup_subq_exit;
520
518
      }
521
519
      if (res > 1)
522
520
      {
526
524
      if (res < 0)
527
525
      {
528
526
        zero_result_cause= "No matching min/max row";
529
 
        error=0;
530
 
        return(0);
 
527
        goto setup_subq_exit;
531
528
      }
532
529
      zero_result_cause= "Select tables optimized away";
533
530
      tables_list= 0;       // All tables resolved
546
543
        COND *table_independent_conds= make_cond_for_table(conds, PSEUDO_TABLE_BITS, 0, 0);
547
544
        conds= table_independent_conds;
548
545
      }
 
546
      goto setup_subq_exit;
549
547
    }
550
548
  }
551
549
  if (!tables_list)
578
576
       select_lex->master_unit() == &session->lex->unit)) // upper level SELECT
579
577
  {
580
578
    zero_result_cause= "no matching row in const table";
581
 
    error= 0;
582
 
    return(0);
 
579
    goto setup_subq_exit;
583
580
  }
584
581
  if (!(session->options & OPTION_BIG_SELECTS) &&
585
582
      best_read > (double) session->variables.max_join_size &&
645
642
  {
646
643
    zero_result_cause=
647
644
      "Impossible WHERE noticed after reading const tables";
648
 
    return(0);        // error == 0
 
645
    goto setup_subq_exit;
649
646
  }
650
647
 
651
648
  error= -1;          /* if goto err */
1110
1107
 
1111
1108
  error= 0;
1112
1109
  return(0);
 
1110
 
 
1111
setup_subq_exit:
 
1112
  /* Even with zero matching rows, subqueries in the HAVING clause
 
1113
     may need to be evaluated if there are aggregate functions in the query.
 
1114
  */
 
1115
  if (setup_subquery_materialization())
 
1116
    return 1;
 
1117
  error= 0;
 
1118
  return 0;
1113
1119
}
1114
1120
 
1115
1121
/**
5385
5391
    join->unit->select_limit_cnt= 1;            // Only send first row
5386
5392
    return(0);
5387
5393
  }
5388
 
  Field **first_field=entry->field+entry->getShare()->fields - field_count;
 
5394
  Field **first_field=entry->getFields() + entry->getShare()->sizeFields() - field_count;
5389
5395
  offset= (field_count ?
5390
 
           entry->field[entry->getShare()->fields - field_count]->
5391
 
           offset(entry->record[0]) : 0);
5392
 
  reclength= entry->getShare()->reclength-offset;
 
5396
           entry->getField(entry->getShare()->sizeFields() - field_count)->offset(entry->record[0]) : 0);
 
5397
  reclength= entry->getShare()->getRecordLength() - offset;
5393
5398
 
5394
5399
  entry->free_io_cache();                               // Safety
5395
5400
  entry->cursor->info(HA_STATUS_VARIABLE);
5396
5401
  if (entry->getShare()->db_type() == heap_engine ||
5397
5402
      (!entry->getShare()->blob_fields &&
5398
5403
       ((ALIGN_SIZE(reclength) + HASH_OVERHEAD) * entry->cursor->stats.records <
5399
 
        session->variables.sortbuff_size)))
 
5404
        session->variables.sortbuff_size)))
 
5405
  {
5400
5406
    error= remove_dup_with_hash_index(join->session, entry,
5401
 
                                     field_count, first_field,
5402
 
                                     reclength, having);
 
5407
                                      field_count, first_field,
 
5408
                                      reclength, having);
 
5409
  }
5403
5410
  else
5404
 
    error= remove_dup_with_compare(join->session, entry, first_field, offset,
5405
 
                                  having);
 
5411
  {
 
5412
    error= remove_dup_with_compare(join->session, entry, first_field, offset, having);
 
5413
  }
5406
5414
 
5407
5415
  free_blobs(first_field);
 
5416
 
5408
5417
  return(error);
5409
5418
}
5410
5419
 
5507
5516
    table->reginfo.join_tab=s;
5508
5517
    table->reginfo.not_exists_optimize=0;
5509
5518
    memset(table->const_key_parts, 0,
5510
 
           sizeof(key_part_map)*table->getShare()->keys);
 
5519
           sizeof(key_part_map)*table->getShare()->sizeKeys());
5511
5520
    all_table_map|= table->map;
5512
5521
    s->join=join;
5513
5522
    s->info=0;                                  // For describe
6045
6054
 
6046
6055
  for (uint32_t i=0 ; i < join_tab->ref.key_parts ; i++)
6047
6056
  {
6048
 
    Field *field=table->field[table->key_info[join_tab->ref.key].key_part[i].
6049
 
                              fieldnr-1];
 
6057
    Field *field=table->getField(table->key_info[join_tab->ref.key].key_part[i].fieldnr - 1);
6050
6058
    Item *value=join_tab->ref.items[i];
6051
6059
    cond->add(new Item_func_equal(new Item_field(field), value));
6052
6060
  }