~thomir-deactivatedaccount/drizzle/drizzle-fix-bug653747

« back to all changes in this revision

Viewing changes to drizzled/transaction_services.cc

Merge Joe

Show diffs side-by-side

added added

removed removed

Lines of Context:
1339
1339
    }
1340
1340
    else
1341
1341
    {
1342
 
      const message::UpdateHeader &update_header= statement->update_header();
1343
 
      string old_table_name= update_header.table_metadata().table_name();
1344
 
 
1345
 
      string current_table_name;
1346
 
      (void) in_table->getShare()->getTableName(current_table_name);
1347
 
      if (current_table_name.compare(old_table_name))
1348
 
      {
1349
 
        finalizeStatementMessage(*statement, in_session);
1350
 
        statement= in_session->getStatementMessage();
1351
 
      }
1352
 
      else
 
1342
      if (useExistingUpdateHeader(*statement, in_table, old_record, new_record))
1353
1343
      {
1354
1344
        /* carry forward the existing segment id */
1355
1345
        const message::UpdateData &current_data= statement->update_data();
1356
1346
        *next_segment_id= current_data.segment_id();
 
1347
      } 
 
1348
      else 
 
1349
      {
 
1350
        finalizeStatementMessage(*statement, in_session);
 
1351
        statement= in_session->getStatementMessage();
1357
1352
      }
1358
1353
    }
1359
1354
  }
1380
1375
  return *statement;
1381
1376
}
1382
1377
 
 
1378
bool TransactionServices::useExistingUpdateHeader(message::Statement &statement,
 
1379
                                                  Table *in_table,
 
1380
                                                  const unsigned char *old_record,
 
1381
                                                  const unsigned char *new_record)
 
1382
{
 
1383
  const message::UpdateHeader &update_header= statement.update_header();
 
1384
  string old_table_name= update_header.table_metadata().table_name();
 
1385
 
 
1386
  string current_table_name;
 
1387
  (void) in_table->getShare()->getTableName(current_table_name);
 
1388
  if (current_table_name.compare(old_table_name))
 
1389
  {
 
1390
    return false;
 
1391
  }
 
1392
  else
 
1393
  {
 
1394
    /* Compare the set fields in the existing UpdateHeader and see if they
 
1395
     * match the updated fields in the new record, if they do not we must
 
1396
     * create a new UpdateHeader 
 
1397
     */
 
1398
    size_t num_set_fields= update_header.set_field_metadata_size();
 
1399
 
 
1400
    Field *current_field;
 
1401
    Field **table_fields= in_table->getFields();
 
1402
    in_table->setReadSet();
 
1403
 
 
1404
    size_t num_calculated_updated_fields= 0;
 
1405
    bool found= false;
 
1406
    while ((current_field= *table_fields++) != NULL)
 
1407
    {
 
1408
      if (num_calculated_updated_fields > num_set_fields)
 
1409
      {
 
1410
        break;
 
1411
      }
 
1412
 
 
1413
      if (isFieldUpdated(current_field, in_table, old_record, new_record))
 
1414
      {
 
1415
        /* check that this field exists in the UpdateHeader record */
 
1416
        found= false;
 
1417
 
 
1418
        for (size_t x= 0; x < num_set_fields; ++x)
 
1419
        {
 
1420
          const message::FieldMetadata &field_metadata= update_header.set_field_metadata(x);
 
1421
          string name= field_metadata.name();
 
1422
          if (name.compare(current_field->field_name) == 0)
 
1423
          {
 
1424
            found= true;
 
1425
            ++num_calculated_updated_fields;
 
1426
            break;
 
1427
          } 
 
1428
        }
 
1429
        if (! found)
 
1430
        {
 
1431
          break;
 
1432
        } 
 
1433
      }
 
1434
    }
 
1435
 
 
1436
    if ((num_calculated_updated_fields == num_set_fields) && found)
 
1437
    {
 
1438
      return true;
 
1439
    } 
 
1440
    else 
 
1441
    {
 
1442
      return false;
 
1443
    }
 
1444
  }
 
1445
}  
 
1446
 
1383
1447
void TransactionServices::setUpdateHeader(message::Statement &statement,
1384
1448
                                          Session *in_session,
1385
1449
                                          Table *in_table,