~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Stewart Smith
  • Date: 2010-04-08 07:20:26 UTC
  • mto: This revision was merged to the branch mainline in revision 1456.
  • Revision ID: stewart@flamingspork.com-20100408072026-w3s8zblhs35uo5mg
removeĀ CHECKSUMĀ TABLE

Show diffs side-by-side

added added

removed removed

Lines of Context:
2267
2267
                                &Cursor::ha_check));
2268
2268
}
2269
2269
 
2270
 
 
2271
 
bool mysql_checksum_table(Session *session, TableList *tables,
2272
 
                          HA_CHECK_OPT *)
2273
 
{
2274
 
  TableList *table;
2275
 
  List<Item> field_list;
2276
 
  Item *item;
2277
 
 
2278
 
  field_list.push_back(item = new Item_empty_string("Table", NAME_LEN*2));
2279
 
  item->maybe_null= 1;
2280
 
  field_list.push_back(item= new Item_int("Checksum", (int64_t) 1,
2281
 
                                          MY_INT64_NUM_DECIMAL_DIGITS));
2282
 
  item->maybe_null= 1;
2283
 
  if (session->client->sendFields(&field_list))
2284
 
    return true;
2285
 
 
2286
 
  /* Open one table after the other to keep lock time as short as possible. */
2287
 
  for (table= tables; table; table= table->next_local)
2288
 
  {
2289
 
    char table_name[NAME_LEN*2+2];
2290
 
    Table *t;
2291
 
 
2292
 
    snprintf(table_name, sizeof(table_name), "%s.%s",table->db,table->table_name);
2293
 
 
2294
 
    t= table->table= session->openTableLock(table, TL_READ);
2295
 
    session->clear_error();                     // these errors shouldn't get client
2296
 
 
2297
 
    session->client->store(table_name);
2298
 
 
2299
 
    if (!t)
2300
 
    {
2301
 
      /* Table didn't exist */
2302
 
      session->client->store();
2303
 
      session->clear_error();
2304
 
    }
2305
 
    else
2306
 
    {
2307
 
      /**
2308
 
        @note if the engine keeps a checksum then we return the checksum, otherwise we calculate
2309
 
      */
2310
 
      if (t->cursor->getEngine()->check_flag(HTON_BIT_HAS_CHECKSUM))
2311
 
      {
2312
 
        session->client->store((uint64_t)t->cursor->checksum());
2313
 
      }
2314
 
      else
2315
 
      {
2316
 
        /* calculating table's checksum */
2317
 
        internal::ha_checksum crc= 0;
2318
 
        unsigned char null_mask=256 -  (1 << t->s->last_null_bit_pos);
2319
 
 
2320
 
        t->use_all_columns();
2321
 
 
2322
 
        if (t->cursor->ha_rnd_init(1))
2323
 
          session->client->store();
2324
 
        else
2325
 
        {
2326
 
          for (;;)
2327
 
          {
2328
 
            internal::ha_checksum row_crc= 0;
2329
 
            int error= t->cursor->rnd_next(t->record[0]);
2330
 
            if (unlikely(error))
2331
 
            {
2332
 
              if (error == HA_ERR_RECORD_DELETED)
2333
 
                continue;
2334
 
              break;
2335
 
            }
2336
 
            if (t->s->null_bytes)
2337
 
            {
2338
 
              /* fix undefined null bits */
2339
 
              t->record[0][t->s->null_bytes-1] |= null_mask;
2340
 
              if (!(t->s->db_create_options & HA_OPTION_PACK_RECORD))
2341
 
                t->record[0][0] |= 1;
2342
 
 
2343
 
              row_crc= internal::my_checksum(row_crc, t->record[0], t->s->null_bytes);
2344
 
            }
2345
 
 
2346
 
            for (uint32_t i= 0; i < t->s->fields; i++ )
2347
 
            {
2348
 
              Field *f= t->field[i];
2349
 
              if ((f->type() == DRIZZLE_TYPE_BLOB) ||
2350
 
                  (f->type() == DRIZZLE_TYPE_VARCHAR))
2351
 
              {
2352
 
                String tmp;
2353
 
                f->val_str(&tmp);
2354
 
                row_crc= internal::my_checksum(row_crc, (unsigned char*) tmp.ptr(), tmp.length());
2355
 
              }
2356
 
              else
2357
 
                row_crc= internal::my_checksum(row_crc, f->ptr,
2358
 
                                     f->pack_length());
2359
 
            }
2360
 
 
2361
 
            crc+= row_crc;
2362
 
          }
2363
 
          session->client->store((uint64_t)crc);
2364
 
          t->cursor->ha_rnd_end();
2365
 
        }
2366
 
      }
2367
 
      session->clear_error();
2368
 
      session->close_thread_tables();
2369
 
      table->table=0;                           // For query cache
2370
 
    }
2371
 
    if (session->client->flush())
2372
 
      goto err;
2373
 
  }
2374
 
 
2375
 
  session->my_eof();
2376
 
  return(false);
2377
 
 
2378
 
 err:
2379
 
  session->close_thread_tables();                       // Shouldn't be needed
2380
 
  if (table)
2381
 
    table->table=0;
2382
 
  return(true);
2383
 
}
2384
 
 
2385
2270
} /* namespace drizzled */