~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_insert.cc

  • Committer: Paul McCullagh
  • Date: 2010-09-22 13:04:27 UTC
  • mto: (1787.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1788.
  • Revision ID: paul.mccullagh@primebase.org-20100922130427-utakdj4ec4uiv1kc
Fixed PBXT recovery and shutdown, added shutdownPlugin() call to all plugins before the plugins are deleted

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
 
17
17
/* Insert of records */
32
32
#include "drizzled/transaction_services.h"
33
33
#include "drizzled/plugin/transactional_storage_engine.h"
34
34
 
35
 
#include "drizzled/table/shell.h"
36
 
 
37
35
namespace drizzled
38
36
{
39
37
 
129
127
      }
130
128
      else
131
129
      {
132
 
        table->setWriteSet(table->timestamp_field->position());
 
130
        table->setWriteSet(table->timestamp_field->field_index);
133
131
      }
134
132
    }
135
133
  }
170
168
      Unmark the timestamp field so that we can check if this is modified
171
169
      by update_fields
172
170
    */
173
 
    timestamp_mark= table->write_set->test(table->timestamp_field->position());
174
 
    table->write_set->reset(table->timestamp_field->position());
 
171
    timestamp_mark= table->write_set->testAndClear(table->timestamp_field->field_index);
175
172
  }
176
173
 
177
174
  /* Check the fields we are going to modify */
189
186
 
190
187
    if (timestamp_mark)
191
188
    {
192
 
      table->setWriteSet(table->timestamp_field->position());
 
189
      table->setWriteSet(table->timestamp_field->field_index);
193
190
    }
194
191
  }
195
192
  return 0;
276
273
                           false,
277
274
                           (fields.elements || !value_count ||
278
275
                            (0) != 0), !ignore))
279
 
  {
280
 
    if (table != NULL)
281
 
      table->cursor->ha_release_auto_increment();
282
 
    if (!joins_freed)
283
 
      free_underlaid_joins(session, &session->lex->select_lex);
284
 
    session->abort_on_warning= 0;
285
 
    DRIZZLE_INSERT_DONE(1, 0);
286
 
    return true;
287
 
  }
 
276
    goto abort;
288
277
 
289
278
  /* mysql_prepare_insert set table_list->table if it was not set */
290
279
  table= table_list->table;
315
304
    if (values->elements != value_count)
316
305
    {
317
306
      my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter);
318
 
 
319
 
      if (table != NULL)
320
 
        table->cursor->ha_release_auto_increment();
321
 
      if (!joins_freed)
322
 
        free_underlaid_joins(session, &session->lex->select_lex);
323
 
      session->abort_on_warning= 0;
324
 
      DRIZZLE_INSERT_DONE(1, 0);
325
 
 
326
 
      return true;
 
307
      goto abort;
327
308
    }
328
309
    if (setup_fields(session, 0, *values, MARK_COLUMNS_READ, 0, 0))
329
 
    {
330
 
      if (table != NULL)
331
 
        table->cursor->ha_release_auto_increment();
332
 
      if (!joins_freed)
333
 
        free_underlaid_joins(session, &session->lex->select_lex);
334
 
      session->abort_on_warning= 0;
335
 
      DRIZZLE_INSERT_DONE(1, 0);
336
 
      return true;
337
 
    }
 
310
      goto abort;
338
311
  }
339
312
  its.rewind ();
340
313
 
478
451
    table->cursor->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
479
452
 
480
453
  if (error)
481
 
  {
482
 
    if (table != NULL)
483
 
      table->cursor->ha_release_auto_increment();
484
 
    if (!joins_freed)
485
 
      free_underlaid_joins(session, &session->lex->select_lex);
486
 
    session->abort_on_warning= 0;
487
 
    DRIZZLE_INSERT_DONE(1, 0);
488
 
    return true;
489
 
  }
490
 
 
 
454
    goto abort;
491
455
  if (values_list.elements == 1 && (!(session->options & OPTION_WARNINGS) ||
492
456
                                    !session->cuted_fields))
493
457
  {
511
475
  session->status_var.inserted_row_count+= session->row_count_func;
512
476
  session->abort_on_warning= 0;
513
477
  DRIZZLE_INSERT_DONE(0, session->row_count_func);
514
 
 
515
478
  return false;
 
479
 
 
480
abort:
 
481
  if (table != NULL)
 
482
    table->cursor->ha_release_auto_increment();
 
483
  if (!joins_freed)
 
484
    free_underlaid_joins(session, &session->lex->select_lex);
 
485
  session->abort_on_warning= 0;
 
486
  DRIZZLE_INSERT_DONE(1, 0);
 
487
  return true;
516
488
}
517
489
 
518
490
 
744
716
{
745
717
  int error;
746
718
  std::vector<unsigned char> key;
747
 
  boost::dynamic_bitset<> *save_read_set, *save_write_set;
 
719
  MyBitmap *save_read_set, *save_write_set;
748
720
  uint64_t prev_insert_id= table->cursor->next_insert_id;
749
721
  uint64_t insert_id_for_cur_row= 0;
750
722
 
846
818
          table->cursor->adjust_next_insert_id_after_explicit_value(
847
819
            table->next_number_field->val_int());
848
820
        info->touched++;
849
 
 
850
 
        if (! table->records_are_comparable() || table->compare_records())
 
821
        if ((table->cursor->getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ) &&
 
822
             !bitmap_is_subset(table->write_set, table->read_set)) ||
 
823
            table->compare_record())
851
824
        {
852
825
          if ((error=table->cursor->updateRecord(table->getUpdateRecord(),
853
826
                                                table->getInsertRecord())) &&
937
910
    */
938
911
    if (table->read_set != save_read_set ||
939
912
        table->write_set != save_write_set)
940
 
      table->column_bitmaps_set(*save_read_set, *save_write_set);
 
913
      table->column_bitmaps_set(save_read_set, save_write_set);
941
914
  }
942
915
  else if ((error=table->cursor->insertRecord(table->getInsertRecord())))
943
916
  {
966
939
 
967
940
before_err:
968
941
  table->cursor->restore_auto_increment(prev_insert_id);
969
 
  table->column_bitmaps_set(*save_read_set, *save_write_set);
970
 
  return 1;
 
942
  table->column_bitmaps_set(save_read_set, save_write_set);
 
943
  return(1);
971
944
}
972
945
 
973
946
 
1487
1460
                                      DrizzleLock **lock,
1488
1461
                                      TableIdentifier &identifier)
1489
1462
{
 
1463
  Table tmp_table;              // Used during 'CreateField()'
1490
1464
  TableShare share(message::Table::INTERNAL);
 
1465
  Table *table= 0;
1491
1466
  uint32_t select_field_count= items->elements;
1492
1467
  /* Add selected items to field list */
1493
1468
  List_iterator_fast<Item> it(*items);
1503
1478
      create_info->table_existed= 1;            // Mark that table existed
1504
1479
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1505
1480
                          ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
1506
 
                          create_table->getTableName());
 
1481
                          create_table->table_name);
1507
1482
      return create_table->table;
1508
1483
    }
1509
1484
 
1510
 
    my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->getTableName());
 
1485
    my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->table_name);
1511
1486
    return NULL;
1512
1487
  }
1513
1488
 
 
1489
  tmp_table.timestamp_field= 0;
 
1490
  tmp_table.setShare(&share);
 
1491
 
 
1492
  tmp_table.getMutableShare()->db_create_options= 0;
 
1493
  tmp_table.getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
 
1494
 
 
1495
  if (not table_proto.engine().name().compare("MyISAM"))
 
1496
    tmp_table.getMutableShare()->db_low_byte_first= true;
 
1497
  else if (not table_proto.engine().name().compare("MEMORY"))
 
1498
    tmp_table.getMutableShare()->db_low_byte_first= true;
 
1499
 
 
1500
  tmp_table.null_row= false;
 
1501
  tmp_table.maybe_null= false;
 
1502
 
 
1503
  while ((item=it++))
1514
1504
  {
1515
 
    table::Shell tmp_table(share);              // Used during 'CreateField()'
1516
 
    tmp_table.timestamp_field= 0;
1517
 
 
1518
 
    tmp_table.getMutableShare()->db_create_options= 0;
1519
 
    tmp_table.getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
1520
 
 
1521
 
    if (not table_proto.engine().name().compare("MyISAM"))
1522
 
      tmp_table.getMutableShare()->db_low_byte_first= true;
1523
 
    else if (not table_proto.engine().name().compare("MEMORY"))
1524
 
      tmp_table.getMutableShare()->db_low_byte_first= true;
1525
 
 
1526
 
    tmp_table.null_row= false;
1527
 
    tmp_table.maybe_null= false;
1528
 
 
1529
 
    tmp_table.in_use= session;
1530
 
 
1531
 
    while ((item=it++))
1532
 
    {
1533
 
      CreateField *cr_field;
1534
 
      Field *field, *def_field;
1535
 
      if (item->type() == Item::FUNC_ITEM)
1536
 
      {
1537
 
        if (item->result_type() != STRING_RESULT)
1538
 
        {
1539
 
          field= item->tmp_table_field(&tmp_table);
1540
 
        }
1541
 
        else
1542
 
        {
1543
 
          field= item->tmp_table_field_from_field_type(&tmp_table, 0);
1544
 
        }
1545
 
      }
 
1505
    CreateField *cr_field;
 
1506
    Field *field, *def_field;
 
1507
    if (item->type() == Item::FUNC_ITEM)
 
1508
      if (item->result_type() != STRING_RESULT)
 
1509
        field= item->tmp_table_field(&tmp_table);
1546
1510
      else
1547
 
      {
1548
 
        field= create_tmp_field(session, &tmp_table, item, item->type(),
1549
 
                                (Item ***) 0, &tmp_field, &def_field, false,
1550
 
                                false, false, 0);
1551
 
      }
1552
 
 
1553
 
      if (!field ||
1554
 
          !(cr_field=new CreateField(field,(item->type() == Item::FIELD_ITEM ?
1555
 
                                            ((Item_field *)item)->field :
1556
 
                                            (Field*) 0))))
1557
 
      {
1558
 
        return NULL;
1559
 
      }
1560
 
 
1561
 
      if (item->maybe_null)
1562
 
      {
1563
 
        cr_field->flags &= ~NOT_NULL_FLAG;
1564
 
      }
1565
 
 
1566
 
      alter_info->create_list.push_back(cr_field);
1567
 
    }
 
1511
        field= item->tmp_table_field_from_field_type(&tmp_table, 0);
 
1512
    else
 
1513
      field= create_tmp_field(session, &tmp_table, item, item->type(),
 
1514
                              (Item ***) 0, &tmp_field, &def_field, false,
 
1515
                              false, false, 0);
 
1516
    if (!field ||
 
1517
        !(cr_field=new CreateField(field,(item->type() == Item::FIELD_ITEM ?
 
1518
                                           ((Item_field *)item)->field :
 
1519
                                           (Field*) 0))))
 
1520
      return NULL;
 
1521
    if (item->maybe_null)
 
1522
      cr_field->flags &= ~NOT_NULL_FLAG;
 
1523
    alter_info->create_list.push_back(cr_field);
1568
1524
  }
1569
1525
 
1570
1526
  /*
1574
1530
    creating base table on which name we have exclusive lock. So code below
1575
1531
    should not cause deadlocks or races.
1576
1532
  */
1577
 
  Table *table= 0;
1578
1533
  {
1579
1534
    if (not mysql_create_table_no_lock(session,
1580
1535
                                       identifier,
1592
1547
          or it was created via different mysqld front-end to the
1593
1548
          cluster. We don't have much options but throw an error.
1594
1549
        */
1595
 
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->getTableName());
 
1550
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->table_name);
1596
1551
        return NULL;
1597
1552
      }
1598
1553
 
1599
1554
      if (not identifier.isTmp())
1600
1555
      {
1601
 
        /* CREATE TABLE... has found that the table already exists for insert and is adapting to use it */
1602
 
        boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex());
1603
 
 
1604
 
        if (create_table->table)
 
1556
        LOCK_open.lock(); /* CREATE TABLE... has found that the table already exists for insert and is adapting to use it */
 
1557
        if (session->reopen_name_locked_table(create_table, false))
1605
1558
        {
1606
 
          table::Concurrent *concurrent_table= static_cast<table::Concurrent *>(create_table->table);
1607
 
 
1608
 
          if (concurrent_table->reopen_name_locked_table(create_table, session))
1609
 
          {
1610
 
            plugin::StorageEngine::dropTable(*session, identifier);
1611
 
          }
1612
 
          else
1613
 
          {
1614
 
            table= create_table->table;
1615
 
          }
 
1559
          quick_rm_table(*session, identifier);
1616
1560
        }
1617
1561
        else
1618
 
        {
1619
 
          plugin::StorageEngine::dropTable(*session, identifier);
1620
 
        }
 
1562
          table= create_table->table;
 
1563
        LOCK_open.unlock();
1621
1564
      }
1622
1565
      else
1623
1566
      {
1630
1573
            it preparable for open. But let us do close_temporary_table() here
1631
1574
            just in case.
1632
1575
          */
1633
 
          session->drop_temporary_table(identifier);
 
1576
          session->drop_temporary_table(create_table);
1634
1577
        }
1635
1578
      }
1636
1579
    }
1637
 
    if (not table)                                   // open failed
 
1580
    if (!table)                                   // open failed
1638
1581
      return NULL;
1639
1582
  }
1640
1583
 
1641
1584
  table->reginfo.lock_type=TL_WRITE;
1642
 
  if (! ((*lock)= session->lockTables(&table, 1, DRIZZLE_LOCK_IGNORE_FLUSH, &not_used)))
 
1585
  if (! ((*lock)= mysql_lock_tables(session, &table, 1,
 
1586
                                    DRIZZLE_LOCK_IGNORE_FLUSH, &not_used)))
1643
1587
  {
1644
1588
    if (*lock)
1645
1589
    {
1646
 
      session->unlockTables(*lock);
 
1590
      mysql_unlock_tables(session, *lock);
1647
1591
      *lock= 0;
1648
1592
    }
1649
1593
 
1704
1648
 
1705
1649
  /* Mark all fields that are given values */
1706
1650
  for (Field **f= field ; *f ; f++)
1707
 
  {
1708
 
    table->setWriteSet((*f)->position());
1709
 
  }
 
1651
    table->setWriteSet((*f)->field_index);
1710
1652
 
1711
1653
  /* Don't set timestamp if used */
1712
1654
  table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
1777
1719
    table->cursor->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
1778
1720
    if (m_plock)
1779
1721
    {
1780
 
      session->unlockTables(*m_plock);
 
1722
      mysql_unlock_tables(session, *m_plock);
1781
1723
      *m_plock= NULL;
1782
1724
      m_plock= NULL;
1783
1725
    }
1807
1749
 
1808
1750
  if (m_plock)
1809
1751
  {
1810
 
    session->unlockTables(*m_plock);
 
1752
    mysql_unlock_tables(session, *m_plock);
1811
1753
    *m_plock= NULL;
1812
1754
    m_plock= NULL;
1813
1755
  }