~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to drizzled/sql_insert.cc

  • Committer: Padraig O'Sullivan
  • Date: 2010-03-15 14:05:26 UTC
  • mfrom: (1237.9.99 staging)
  • Revision ID: osullivan.padraig@gmail.com-20100315140526-opbgwdwn6tfecdkq
MergeĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include "drizzled/sql_table.h"
30
30
#include "drizzled/pthread_globals.h"
31
31
#include "drizzled/transaction_services.h"
 
32
#include "drizzled/plugin/transactional_storage_engine.h"
32
33
 
33
34
namespace drizzled
34
35
{
381
382
    }
382
383
 
383
384
    // Release latches in case bulk insert takes a long time
384
 
    plugin::StorageEngine::releaseTemporaryLatches(session);
 
385
    plugin::TransactionalStorageEngine::releaseTemporaryLatches(session);
385
386
 
386
387
    error=write_record(session, table ,&info);
387
388
    if (error)
413
414
    transactional_table= table->cursor->has_transactions();
414
415
 
415
416
    changed= (info.copied || info.deleted || info.updated);
416
 
    if ((changed && error <= 0) || session->transaction.stmt.modified_non_trans_table)
 
417
    if ((changed && error <= 0) || session->transaction.stmt.hasModifiedNonTransData())
417
418
    {
418
 
      if (session->transaction.stmt.modified_non_trans_table)
419
 
        session->transaction.all.modified_non_trans_table= true;
 
419
      if (session->transaction.stmt.hasModifiedNonTransData())
 
420
        session->transaction.all.markModifiedNonTransData();
420
421
    }
421
 
    assert(transactional_table || !changed || session->transaction.stmt.modified_non_trans_table);
 
422
    assert(transactional_table || !changed || session->transaction.stmt.hasModifiedNonTransData());
422
423
 
423
424
  }
424
425
  session->set_proc_info("end");
696
697
    then both on update triggers will work instead. Similarly both on
697
698
    delete triggers will be invoked if we will delete conflicting records.
698
699
 
699
 
    Sets session->transaction.stmt.modified_non_trans_table to true if table which is updated didn't have
 
700
    Sets session->transaction.stmt.modified_non_trans_data to true if table which is updated didn't have
700
701
    transactions.
701
702
 
702
703
  RETURN VALUE
895
896
            goto err;
896
897
          info->deleted++;
897
898
          if (!table->cursor->has_transactions())
898
 
            session->transaction.stmt.modified_non_trans_table= true;
 
899
            session->transaction.stmt.markModifiedNonTransData();
899
900
          /* Let us attempt do write_row() once more */
900
901
        }
901
902
      }
926
927
  if (key)
927
928
    free(key);
928
929
  if (!table->cursor->has_transactions())
929
 
    session->transaction.stmt.modified_non_trans_table= true;
 
930
    session->transaction.stmt.markModifiedNonTransData();
930
931
  return(0);
931
932
 
932
933
err:
1253
1254
    return(1);
1254
1255
 
1255
1256
  // Release latches in case bulk insert takes a long time
1256
 
  plugin::StorageEngine::releaseTemporaryLatches(session);
 
1257
  plugin::TransactionalStorageEngine::releaseTemporaryLatches(session);
1257
1258
 
1258
1259
  error= write_record(session, table, &info);
1259
1260
 
1326
1327
      We must invalidate the table in the query cache before binlog writing
1327
1328
      and ha_autocommit_or_rollback.
1328
1329
    */
1329
 
    if (session->transaction.stmt.modified_non_trans_table)
1330
 
      session->transaction.all.modified_non_trans_table= true;
 
1330
    if (session->transaction.stmt.hasModifiedNonTransData())
 
1331
      session->transaction.all.markModifiedNonTransData();
1331
1332
  }
1332
1333
  assert(trans_table || !changed ||
1333
 
              session->transaction.stmt.modified_non_trans_table);
 
1334
              session->transaction.stmt.hasModifiedNonTransData());
1334
1335
 
1335
1336
  table->cursor->ha_release_auto_increment();
1336
1337
 
1392
1393
    changed= (info.copied || info.deleted || info.updated);
1393
1394
    transactional_table= table->cursor->has_transactions();
1394
1395
    assert(transactional_table || !changed ||
1395
 
                session->transaction.stmt.modified_non_trans_table);
 
1396
                session->transaction.stmt.hasModifiedNonTransData());
1396
1397
    table->cursor->ha_release_auto_increment();
1397
1398
  }
1398
1399
 
1453
1454
 
1454
1455
static Table *create_table_from_items(Session *session, HA_CREATE_INFO *create_info,
1455
1456
                                      TableList *create_table,
1456
 
                                      message::Table *table_proto,
 
1457
                                      message::Table &table_proto,
1457
1458
                                      AlterInfo *alter_info,
1458
1459
                                      List<Item> *items,
1459
1460
                                      bool is_if_not_exists,
1469
1470
  Field *tmp_field;
1470
1471
  bool not_used;
1471
1472
 
1472
 
  bool lex_identified_temp_table= (table_proto->type() == message::Table::TEMPORARY);
 
1473
  bool lex_identified_temp_table= (table_proto.type() == message::Table::TEMPORARY);
1473
1474
 
1474
 
  if (!(lex_identified_temp_table) &&
 
1475
  if (not (lex_identified_temp_table) &&
1475
1476
      create_table->table->db_stat)
1476
1477
  {
1477
1478
    /* Table already exists and was open at openTablesLock() stage. */
1494
1495
 
1495
1496
  tmp_table.s->db_create_options=0;
1496
1497
  tmp_table.s->blob_ptr_size= portable_sizeof_char_ptr;
1497
 
  tmp_table.s->db_low_byte_first=
1498
 
        test(create_info->db_type == myisam_engine ||
1499
 
             create_info->db_type == heap_engine);
 
1498
 
 
1499
  if (not table_proto.engine().name().compare("MyISAM"))
 
1500
    tmp_table.s->db_low_byte_first= true;
 
1501
  else if (not table_proto.engine().name().compare("MEMORY"))
 
1502
    tmp_table.s->db_low_byte_first= true;
 
1503
 
1500
1504
  tmp_table.null_row= false;
1501
1505
  tmp_table.maybe_null= false;
1502
1506
 
1526
1530
  TableIdentifier identifier(create_table->db,
1527
1531
                             create_table->table_name,
1528
1532
                             lex_identified_temp_table ?  TEMP_TABLE :
1529
 
                             NO_TMP_TABLE);
 
1533
                             STANDARD_TABLE);
1530
1534
 
1531
1535
 
1532
1536
  /*
1537
1541
    should not cause deadlocks or races.
1538
1542
  */
1539
1543
  {
1540
 
    if (!mysql_create_table_no_lock(session,
 
1544
    if (not mysql_create_table_no_lock(session,
1541
1545
                                    identifier,
1542
1546
                                    create_info,
1543
1547
                                    table_proto,
1558
1562
        return NULL;
1559
1563
      }
1560
1564
 
1561
 
      if (!(lex_identified_temp_table))
 
1565
      if (not lex_identified_temp_table)
1562
1566
      {
1563
1567
        pthread_mutex_lock(&LOCK_open); /* CREATE TABLE... has found that the table already exists for insert and is adapting to use it */
1564
1568
        if (session->reopen_name_locked_table(create_table, false))
1571
1575
      }
1572
1576
      else
1573
1577
      {
1574
 
        if (!(table= session->openTable(create_table, (bool*) 0,
1575
 
                                         DRIZZLE_OPEN_TEMPORARY_ONLY)) &&
1576
 
            !create_info->table_existed)
 
1578
        if (not (table= session->openTable(create_table, (bool*) 0,
 
1579
                                           DRIZZLE_OPEN_TEMPORARY_ONLY)) &&
 
1580
            not create_info->table_existed)
1577
1581
        {
1578
1582
          /*
1579
1583
            This shouldn't happen as creation of temporary table should make
1610
1614
int
1611
1615
select_create::prepare(List<Item> &values, Select_Lex_Unit *u)
1612
1616
{
1613
 
  bool lex_identified_temp_table= (table_proto->type() == message::Table::TEMPORARY);
 
1617
  bool lex_identified_temp_table= (table_proto.type() == message::Table::TEMPORARY);
1614
1618
 
1615
1619
  DRIZZLE_LOCK *extra_lock= NULL;
1616
1620
  /*
1617
 
    For row-based replication, the CREATE-SELECT statement is written
1618
 
    in two pieces: the first one contain the CREATE TABLE statement
1619
 
    necessary to create the table and the second part contain the rows
1620
 
    that should go into the table.
1621
 
 
1622
 
    For non-temporary tables, the start of the CREATE-SELECT
1623
 
    implicitly commits the previous transaction, and all events
1624
 
    forming the statement will be stored the transaction cache. At end
1625
 
    of the statement, the entire statement is committed as a
1626
 
    transaction, and all events are written to the binary log.
1627
 
 
1628
 
    On the master, the table is locked for the duration of the
1629
 
    statement, but since the CREATE part is replicated as a simple
1630
 
    statement, there is no way to lock the table for accesses on the
1631
 
    slave.  Hence, we have to hold on to the CREATE part of the
1632
 
    statement until the statement has finished.
 
1621
    For replication, the CREATE-SELECT statement is written
 
1622
    in two pieces: the first transaction messsage contains 
 
1623
    the CREATE TABLE statement as a CreateTableStatement message
 
1624
    necessary to create the table.
 
1625
    
 
1626
    The second transaction message contains all the InsertStatement
 
1627
    and associated InsertRecords that should go into the table.
1633
1628
   */
1634
1629
 
1635
1630
  unit= u;
1636
1631
 
1637
 
  /*
1638
 
    Start a statement transaction before the create if we are using
1639
 
    row-based replication for the statement.  If we are creating a
1640
 
    temporary table, we need to start a statement transaction.
1641
 
  */
1642
 
 
1643
1632
  if (!(table= create_table_from_items(session, create_info, create_table,
1644
1633
                                       table_proto,
1645
1634
                                       alter_info, &values,
1701
1690
 
1702
1691
void select_create::send_error(uint32_t errcode,const char *err)
1703
1692
{
1704
 
 
1705
 
 
1706
1693
  /*
1707
1694
    This will execute any rollbacks that are necessary before writing
1708
1695
    the transcation cache.
1754
1741
 
1755
1742
void select_create::abort()
1756
1743
{
1757
 
 
1758
 
 
1759
1744
  /*
1760
1745
    In select_insert::abort() we roll back the statement, including
1761
1746
    truncating the transaction cache of the binary log. To do this, we
1772
1757
    log state.
1773
1758
  */
1774
1759
  select_insert::abort();
1775
 
  session->transaction.stmt.modified_non_trans_table= false;
1776
 
 
1777
1760
 
1778
1761
  if (m_plock)
1779
1762
  {