~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/opt_sum.cc

  • Committer: Brian Aker
  • Date: 2009-11-12 16:13:04 UTC
  • mfrom: (1211.1.7 staging)
  • Revision ID: brian@gaz-20091112161304-opamiauv36fg0n6u
Rollup of Brian, Padraig, and Stewart patches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
  uint64_t count= 1;
82
82
  for (TableList *tl= tables; tl; tl= tl->next_leaf)
83
83
  {
84
 
    ha_rows tmp= tl->table->file->records();
 
84
    ha_rows tmp= tl->table->cursor->records();
85
85
    if ((tmp == HA_POS_ERROR))
86
86
      return UINT64_MAX;
87
87
    count*= tmp;
162
162
      Schema tables are filled after this function is invoked, so we can't
163
163
      get row count
164
164
    */
165
 
    if (!(tl->table->file->ha_table_flags() & HA_STATS_RECORDS_IS_EXACT) ||
 
165
    if (!(tl->table->cursor->ha_table_flags() & HA_STATS_RECORDS_IS_EXACT) ||
166
166
        tl->schema_table)
167
167
    {
168
168
      maybe_exact_count&= test(!tl->schema_table &&
169
 
                               (tl->table->file->ha_table_flags() &
 
169
                               (tl->table->cursor->ha_table_flags() &
170
170
                                HA_HAS_RECORDS));
171
171
      is_exact_count= false;
172
172
      count= 1;                                 // ensure count != 0
173
173
    }
174
174
    else
175
175
    {
176
 
      error= tl->table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
 
176
      error= tl->table->cursor->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
177
177
      if(error)
178
178
      {
179
 
        tl->table->file->print_error(error, MYF(ME_FATALERROR));
 
179
        tl->table->cursor->print_error(error, MYF(ME_FATALERROR));
180
180
        return error;
181
181
      }
182
 
      count*= tl->table->file->stats.records;
 
182
      count*= tl->table->cursor->stats.records;
183
183
    }
184
184
  }
185
185
 
245
245
            Type of range for the key part for this field will be
246
246
            returned in range_fl.
247
247
          */
248
 
          if (table->file->inited || (outer_tables & table->map) ||
 
248
          if (table->cursor->inited || (outer_tables & table->map) ||
249
249
              !find_key_for_maxmin(0, &ref, item_field->field, conds,
250
250
                                   &range_fl, &prefix_len))
251
251
          {
252
252
            const_result= 0;
253
253
            break;
254
254
          }
255
 
          error= table->file->ha_index_init((uint32_t) ref.key, 1);
 
255
          error= table->cursor->ha_index_init((uint32_t) ref.key, 1);
256
256
 
257
257
          if (!ref.key_length)
258
 
            error= table->file->index_first(table->record[0]);
 
258
            error= table->cursor->index_first(table->record[0]);
259
259
          else
260
260
          {
261
261
            /*
277
277
                 Closed interval: Either The MIN argument is non-nullable, or
278
278
                 we have a >= predicate for the MIN argument.
279
279
              */
280
 
              error= table->file->index_read_map(table->record[0],
 
280
              error= table->cursor->index_read_map(table->record[0],
281
281
                                                 ref.key_buff,
282
282
                                                 make_prev_keypart_map(ref.key_parts),
283
283
                                                 HA_READ_KEY_OR_NEXT);
289
289
                2) there is a > predicate on it, nullability is irrelevant.
290
290
                We need to scan the next bigger record first.
291
291
              */
292
 
              error= table->file->index_read_map(table->record[0],
 
292
              error= table->cursor->index_read_map(table->record[0],
293
293
                                                 ref.key_buff,
294
294
                                                 make_prev_keypart_map(ref.key_parts),
295
295
                                                 HA_READ_AFTER_KEY);
315
315
                   key_cmp_if_same(table, ref.key_buff, ref.key, prefix_len)))
316
316
              {
317
317
                assert(item_field->field->real_maybe_null());
318
 
                error= table->file->index_read_map(table->record[0],
 
318
                error= table->cursor->index_read_map(table->record[0],
319
319
                                                   ref.key_buff,
320
320
                                                   make_prev_keypart_map(ref.key_parts),
321
321
                                                   HA_READ_KEY_EXACT);
329
329
          if (table->key_read)
330
330
          {
331
331
            table->key_read= 0;
332
 
            table->file->extra(HA_EXTRA_NO_KEYREAD);
 
332
            table->cursor->extra(HA_EXTRA_NO_KEYREAD);
333
333
          }
334
 
          table->file->ha_index_end();
 
334
          table->cursor->ha_index_end();
335
335
          if (error)
336
336
          {
337
337
            if (error == HA_ERR_KEY_NOT_FOUND || error == HA_ERR_END_OF_FILE)
338
338
              return HA_ERR_KEY_NOT_FOUND;            // No rows matching WHERE
339
339
            /* HA_ERR_LOCK_DEADLOCK or some other error */
340
 
            table->file->print_error(error, MYF(0));
 
340
            table->cursor->print_error(error, MYF(0));
341
341
            return(error);
342
342
          }
343
343
          removed_tables|= table->map;
393
393
            Type of range for the key part for this field will be
394
394
            returned in range_fl.
395
395
          */
396
 
          if (table->file->inited || (outer_tables & table->map) ||
 
396
          if (table->cursor->inited || (outer_tables & table->map) ||
397
397
                  !find_key_for_maxmin(1, &ref, item_field->field, conds,
398
398
                                                   &range_fl, &prefix_len))
399
399
          {
400
400
            const_result= 0;
401
401
            break;
402
402
          }
403
 
          error= table->file->ha_index_init((uint32_t) ref.key, 1);
 
403
          error= table->cursor->ha_index_init((uint32_t) ref.key, 1);
404
404
 
405
405
          if (!ref.key_length)
406
 
            error= table->file->index_last(table->record[0]);
 
406
            error= table->cursor->index_last(table->record[0]);
407
407
          else
408
 
            error= table->file->index_read_map(table->record[0], key_buff,
 
408
            error= table->cursor->index_read_map(table->record[0], key_buff,
409
409
                                               make_prev_keypart_map(ref.key_parts),
410
410
                                               range_fl & NEAR_MAX ?
411
411
                                               HA_READ_BEFORE_KEY :
416
416
          if (table->key_read)
417
417
          {
418
418
            table->key_read=0;
419
 
            table->file->extra(HA_EXTRA_NO_KEYREAD);
 
419
            table->cursor->extra(HA_EXTRA_NO_KEYREAD);
420
420
          }
421
 
          table->file->ha_index_end();
 
421
          table->cursor->ha_index_end();
422
422
          if (error)
423
423
          {
424
424
            if (error == HA_ERR_KEY_NOT_FOUND || error == HA_ERR_END_OF_FILE)
425
425
              return HA_ERR_KEY_NOT_FOUND;           // No rows matching WHERE
426
426
            /* HA_ERR_LOCK_DEADLOCK or some other error */
427
 
            table->file->print_error(error, MYF(ME_FATALERROR));
 
427
            table->cursor->print_error(error, MYF(ME_FATALERROR));
428
428
            return(error);
429
429
          }
430
430
          removed_tables|= table->map;
829
829
         part != part_end ;
830
830
         part++, jdx++, key_part_to_use= (key_part_to_use << 1) | 1)
831
831
    {
832
 
      if (!(table->file->index_flags(idx, jdx, 0) & HA_READ_ORDER))
 
832
      if (!(table->cursor->index_flags(idx, jdx, 0) & HA_READ_ORDER))
833
833
        return 0;
834
834
 
835
835
      /* Check whether the index component is partial */
882
882
          if (field->part_of_key.test(idx))
883
883
          {
884
884
            table->key_read= 1;
885
 
            table->file->extra(HA_EXTRA_KEYREAD);
 
885
            table->cursor->extra(HA_EXTRA_KEYREAD);
886
886
          }
887
887
          return 1;
888
888
        }