~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_insert.cc

  • Committer: Monty Taylor
  • Date: 2010-10-19 21:58:26 UTC
  • mfrom: (1861.3.7 ld-version-script)
  • mto: This revision was merged to the branch mainline in revision 1863.
  • Revision ID: mordred@inaugust.com-20101019215826-ofh15co6vp47vndb
Merge Monty - Fixed the valgrind errors, made it so that haildb works in trunk with no extra magic.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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->test(table->timestamp_field->field_index);
 
172
    table->write_set->reset(table->timestamp_field->field_index);
175
173
  }
176
174
 
177
175
  /* Check the fields we are going to modify */
189
187
 
190
188
    if (timestamp_mark)
191
189
    {
192
 
      table->setWriteSet(table->timestamp_field->position());
 
190
      table->setWriteSet(table->timestamp_field->field_index);
193
191
    }
194
192
  }
195
193
  return 0;
276
274
                           false,
277
275
                           (fields.elements || !value_count ||
278
276
                            (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
 
  }
 
277
    goto abort;
288
278
 
289
279
  /* mysql_prepare_insert set table_list->table if it was not set */
290
280
  table= table_list->table;
315
305
    if (values->elements != value_count)
316
306
    {
317
307
      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;
 
308
      goto abort;
327
309
    }
328
310
    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
 
    }
 
311
      goto abort;
338
312
  }
339
313
  its.rewind ();
340
314
 
478
452
    table->cursor->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
479
453
 
480
454
  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
 
 
 
455
    goto abort;
491
456
  if (values_list.elements == 1 && (!(session->options & OPTION_WARNINGS) ||
492
457
                                    !session->cuted_fields))
493
458
  {
511
476
  session->status_var.inserted_row_count+= session->row_count_func;
512
477
  session->abort_on_warning= 0;
513
478
  DRIZZLE_INSERT_DONE(0, session->row_count_func);
514
 
 
515
479
  return false;
 
480
 
 
481
abort:
 
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;
516
489
}
517
490
 
518
491
 
846
819
          table->cursor->adjust_next_insert_id_after_explicit_value(
847
820
            table->next_number_field->val_int());
848
821
        info->touched++;
849
 
 
850
 
        if (! table->records_are_comparable() || table->compare_records())
 
822
        if ((table->cursor->getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ) &&
 
823
            ! table->write_set->is_subset_of(*table->read_set)) ||
 
824
            table->compare_record())
851
825
        {
852
826
          if ((error=table->cursor->updateRecord(table->getUpdateRecord(),
853
827
                                                table->getInsertRecord())) &&
1487
1461
                                      DrizzleLock **lock,
1488
1462
                                      TableIdentifier &identifier)
1489
1463
{
 
1464
  Table tmp_table;              // Used during 'CreateField()'
1490
1465
  TableShare share(message::Table::INTERNAL);
 
1466
  Table *table= 0;
1491
1467
  uint32_t select_field_count= items->elements;
1492
1468
  /* Add selected items to field list */
1493
1469
  List_iterator_fast<Item> it(*items);
1503
1479
      create_info->table_existed= 1;            // Mark that table existed
1504
1480
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1505
1481
                          ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
1506
 
                          create_table->getTableName());
 
1482
                          create_table->table_name);
1507
1483
      return create_table->table;
1508
1484
    }
1509
1485
 
1510
 
    my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->getTableName());
 
1486
    my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->table_name);
1511
1487
    return NULL;
1512
1488
  }
1513
1489
 
 
1490
  tmp_table.timestamp_field= 0;
 
1491
  tmp_table.setShare(&share);
 
1492
 
 
1493
  tmp_table.getMutableShare()->db_create_options= 0;
 
1494
  tmp_table.getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
 
1495
 
 
1496
  if (not table_proto.engine().name().compare("MyISAM"))
 
1497
    tmp_table.getMutableShare()->db_low_byte_first= true;
 
1498
  else if (not table_proto.engine().name().compare("MEMORY"))
 
1499
    tmp_table.getMutableShare()->db_low_byte_first= true;
 
1500
 
 
1501
  tmp_table.null_row= false;
 
1502
  tmp_table.maybe_null= false;
 
1503
 
 
1504
  tmp_table.in_use= session;
 
1505
 
 
1506
  while ((item=it++))
1514
1507
  {
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++))
 
1508
    CreateField *cr_field;
 
1509
    Field *field, *def_field;
 
1510
    if (item->type() == Item::FUNC_ITEM)
1532
1511
    {
1533
 
      CreateField *cr_field;
1534
 
      Field *field, *def_field;
1535
 
      if (item->type() == Item::FUNC_ITEM)
 
1512
      if (item->result_type() != STRING_RESULT)
1536
1513
      {
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
 
        }
 
1514
        field= item->tmp_table_field(&tmp_table);
1545
1515
      }
1546
1516
      else
1547
1517
      {
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
 
    }
 
1518
        field= item->tmp_table_field_from_field_type(&tmp_table, 0);
 
1519
      }
 
1520
    }
 
1521
    else
 
1522
    {
 
1523
      field= create_tmp_field(session, &tmp_table, item, item->type(),
 
1524
                              (Item ***) 0, &tmp_field, &def_field, false,
 
1525
                              false, false, 0);
 
1526
    }
 
1527
 
 
1528
    if (!field ||
 
1529
        !(cr_field=new CreateField(field,(item->type() == Item::FIELD_ITEM ?
 
1530
                                           ((Item_field *)item)->field :
 
1531
                                           (Field*) 0))))
 
1532
    {
 
1533
      return NULL;
 
1534
    }
 
1535
 
 
1536
    if (item->maybe_null)
 
1537
    {
 
1538
      cr_field->flags &= ~NOT_NULL_FLAG;
 
1539
    }
 
1540
 
 
1541
    alter_info->create_list.push_back(cr_field);
1568
1542
  }
1569
1543
 
1570
1544
  /*
1574
1548
    creating base table on which name we have exclusive lock. So code below
1575
1549
    should not cause deadlocks or races.
1576
1550
  */
1577
 
  Table *table= 0;
1578
1551
  {
1579
1552
    if (not mysql_create_table_no_lock(session,
1580
1553
                                       identifier,
1592
1565
          or it was created via different mysqld front-end to the
1593
1566
          cluster. We don't have much options but throw an error.
1594
1567
        */
1595
 
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->getTableName());
 
1568
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->table_name);
1596
1569
        return NULL;
1597
1570
      }
1598
1571
 
1599
1572
      if (not identifier.isTmp())
1600
1573
      {
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)
 
1574
        LOCK_open.lock(); /* CREATE TABLE... has found that the table already exists for insert and is adapting to use it */
 
1575
        if (session->reopen_name_locked_table(create_table, false))
1605
1576
        {
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
 
          }
 
1577
          quick_rm_table(*session, identifier);
1616
1578
        }
1617
1579
        else
1618
 
        {
1619
 
          plugin::StorageEngine::dropTable(*session, identifier);
1620
 
        }
 
1580
          table= create_table->table;
 
1581
        LOCK_open.unlock();
1621
1582
      }
1622
1583
      else
1623
1584
      {
1630
1591
            it preparable for open. But let us do close_temporary_table() here
1631
1592
            just in case.
1632
1593
          */
1633
 
          session->drop_temporary_table(identifier);
 
1594
          session->drop_temporary_table(create_table);
1634
1595
        }
1635
1596
      }
1636
1597
    }
1637
 
    if (not table)                                   // open failed
 
1598
    if (!table)                                   // open failed
1638
1599
      return NULL;
1639
1600
  }
1640
1601
 
1641
1602
  table->reginfo.lock_type=TL_WRITE;
1642
 
  if (! ((*lock)= session->lockTables(&table, 1, DRIZZLE_LOCK_IGNORE_FLUSH, &not_used)))
 
1603
  if (! ((*lock)= mysql_lock_tables(session, &table, 1,
 
1604
                                    DRIZZLE_LOCK_IGNORE_FLUSH, &not_used)))
1643
1605
  {
1644
1606
    if (*lock)
1645
1607
    {
1646
 
      session->unlockTables(*lock);
 
1608
      mysql_unlock_tables(session, *lock);
1647
1609
      *lock= 0;
1648
1610
    }
1649
1611
 
1704
1666
 
1705
1667
  /* Mark all fields that are given values */
1706
1668
  for (Field **f= field ; *f ; f++)
1707
 
  {
1708
 
    table->setWriteSet((*f)->position());
1709
 
  }
 
1669
    table->setWriteSet((*f)->field_index);
1710
1670
 
1711
1671
  /* Don't set timestamp if used */
1712
1672
  table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
1777
1737
    table->cursor->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
1778
1738
    if (m_plock)
1779
1739
    {
1780
 
      session->unlockTables(*m_plock);
 
1740
      mysql_unlock_tables(session, *m_plock);
1781
1741
      *m_plock= NULL;
1782
1742
      m_plock= NULL;
1783
1743
    }
1807
1767
 
1808
1768
  if (m_plock)
1809
1769
  {
1810
 
    session->unlockTables(*m_plock);
 
1770
    mysql_unlock_tables(session, *m_plock);
1811
1771
    *m_plock= NULL;
1812
1772
    m_plock= NULL;
1813
1773
  }