~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_insert.cc

  • Committer: Brian Aker
  • Date: 2010-06-03 22:55:32 UTC
  • mto: (1578.6.9 explain-drizzle)
  • mto: This revision was merged to the branch mainline in revision 1591.
  • Revision ID: brian@gir-2.local-20100603225532-5yuc8um41i4owavf
Additional pass through to remove raw field access.

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
 
123
121
    if (table->timestamp_field) // Don't automaticly set timestamp if used
124
122
    {
125
123
      if (table->timestamp_field->isWriteSet())
126
 
      {
127
124
        clear_timestamp_auto_bits(table->timestamp_field_type,
128
125
                                  TIMESTAMP_AUTO_SET_ON_INSERT);
129
 
      }
130
126
      else
131
127
      {
132
 
        table->setWriteSet(table->timestamp_field->position());
 
128
        table->setWriteSet(table->timestamp_field->field_index);
133
129
      }
134
130
    }
135
131
  }
170
166
      Unmark the timestamp field so that we can check if this is modified
171
167
      by update_fields
172
168
    */
173
 
    timestamp_mark= table->write_set->test(table->timestamp_field->position());
174
 
    table->write_set->reset(table->timestamp_field->position());
 
169
    timestamp_mark= table->write_set->testAndClear(table->timestamp_field->field_index);
175
170
  }
176
171
 
177
172
  /* Check the fields we are going to modify */
182
177
  {
183
178
    /* Don't set timestamp column if this is modified. */
184
179
    if (table->timestamp_field->isWriteSet())
185
 
    {
186
180
      clear_timestamp_auto_bits(table->timestamp_field_type,
187
181
                                TIMESTAMP_AUTO_SET_ON_UPDATE);
188
 
    }
189
 
 
190
182
    if (timestamp_mark)
191
 
    {
192
 
      table->setWriteSet(table->timestamp_field->position());
193
 
    }
 
183
      table->setWriteSet(table->timestamp_field->field_index);
194
184
  }
195
185
  return 0;
196
186
}
241
231
  uint32_t value_count;
242
232
  ulong counter = 1;
243
233
  uint64_t id;
244
 
  CopyInfo info;
 
234
  COPY_INFO info;
245
235
  Table *table= 0;
246
236
  List_iterator_fast<List_item> its(values_list);
247
237
  List_item *values;
276
266
                           false,
277
267
                           (fields.elements || !value_count ||
278
268
                            (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
 
  }
 
269
    goto abort;
288
270
 
289
271
  /* mysql_prepare_insert set table_list->table if it was not set */
290
272
  table= table_list->table;
315
297
    if (values->elements != value_count)
316
298
    {
317
299
      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;
 
300
      goto abort;
327
301
    }
328
302
    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
 
    }
 
303
      goto abort;
338
304
  }
339
305
  its.rewind ();
340
306
 
344
310
  /*
345
311
    Fill in the given fields and dump it to the table cursor
346
312
  */
 
313
  memset(&info, 0, sizeof(info));
347
314
  info.ignore= ignore;
348
315
  info.handle_duplicates=duplic;
349
316
  info.update_fields= &update_fields;
354
321
    For single line insert, generate an error if try to set a NOT NULL field
355
322
    to NULL.
356
323
  */
357
 
  session->count_cuted_fields= ignore ? CHECK_FIELD_WARN : CHECK_FIELD_ERROR_FOR_NULL;
358
 
 
 
324
  session->count_cuted_fields= ((values_list.elements == 1 &&
 
325
                                 !ignore) ?
 
326
                                CHECK_FIELD_ERROR_FOR_NULL :
 
327
                                CHECK_FIELD_WARN);
359
328
  session->cuted_fields = 0L;
360
329
  table->next_number_field=table->found_next_number_field;
361
330
 
401
370
    {
402
371
      table->restoreRecordAsDefault();  // Get empty record
403
372
 
404
 
      if (fill_record(session, table->getFields(), *values))
 
373
      if (fill_record(session, table->field, *values))
405
374
      {
406
375
        if (values_list.elements != 1 && ! session->is_error())
407
376
        {
478
447
    table->cursor->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
479
448
 
480
449
  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
 
 
 
450
    goto abort;
491
451
  if (values_list.elements == 1 && (!(session->options & OPTION_WARNINGS) ||
492
452
                                    !session->cuted_fields))
493
453
  {
508
468
    session->my_ok((ulong) session->row_count_func,
509
469
                   info.copied + info.deleted + info.touched, id, buff);
510
470
  }
511
 
  session->status_var.inserted_row_count+= session->row_count_func;
512
471
  session->abort_on_warning= 0;
513
472
  DRIZZLE_INSERT_DONE(0, session->row_count_func);
514
 
 
515
473
  return false;
 
474
 
 
475
abort:
 
476
  if (table != NULL)
 
477
    table->cursor->ha_release_auto_increment();
 
478
  if (!joins_freed)
 
479
    free_underlaid_joins(session, &session->lex->select_lex);
 
480
  session->abort_on_warning= 0;
 
481
  DRIZZLE_INSERT_DONE(1, 0);
 
482
  return true;
516
483
}
517
484
 
518
485
 
721
688
     write_record()
722
689
      session   - thread context
723
690
      table - table to which record should be written
724
 
      info  - CopyInfo structure describing handling of duplicates
 
691
      info  - COPY_INFO structure describing handling of duplicates
725
692
              and which is used for counting number of records inserted
726
693
              and deleted.
727
694
 
740
707
*/
741
708
 
742
709
 
743
 
int write_record(Session *session, Table *table,CopyInfo *info)
 
710
int write_record(Session *session, Table *table,COPY_INFO *info)
744
711
{
745
712
  int error;
746
 
  std::vector<unsigned char> key;
747
 
  boost::dynamic_bitset<> *save_read_set, *save_write_set;
 
713
  char *key=0;
 
714
  MyBitmap *save_read_set, *save_write_set;
748
715
  uint64_t prev_insert_id= table->cursor->next_insert_id;
749
716
  uint64_t insert_id_for_cur_row= 0;
750
717
 
755
722
 
756
723
  if (info->handle_duplicates == DUP_REPLACE || info->handle_duplicates == DUP_UPDATE)
757
724
  {
758
 
    while ((error=table->cursor->insertRecord(table->getInsertRecord())))
 
725
    while ((error=table->cursor->insertRecord(table->record[0])))
759
726
    {
760
727
      uint32_t key_nr;
761
728
      /*
803
770
        goto err;
804
771
      if (table->cursor->getEngine()->check_flag(HTON_BIT_DUPLICATE_POS))
805
772
      {
806
 
        if (table->cursor->rnd_pos(table->getUpdateRecord(),table->cursor->dup_ref))
 
773
        if (table->cursor->rnd_pos(table->record[1],table->cursor->dup_ref))
807
774
          goto err;
808
775
      }
809
776
      else
814
781
          goto err;
815
782
        }
816
783
 
817
 
        if (not key.size())
 
784
        if (!key)
818
785
        {
819
 
          key.resize(table->getShare()->max_unique_length);
 
786
          if (!(key=(char*) malloc(table->getShare()->max_unique_length)))
 
787
          {
 
788
            error=ENOMEM;
 
789
            goto err;
 
790
          }
820
791
        }
821
 
        key_copy(&key[0], table->getInsertRecord(), table->key_info+key_nr, 0);
822
 
        if ((error=(table->cursor->index_read_idx_map(table->getUpdateRecord(),key_nr,
823
 
                                                    &key[0], HA_WHOLE_KEY,
 
792
        key_copy((unsigned char*) key,table->record[0],table->key_info+key_nr,0);
 
793
        if ((error=(table->cursor->index_read_idx_map(table->record[1],key_nr,
 
794
                                                    (unsigned char*) key, HA_WHOLE_KEY,
824
795
                                                    HA_READ_KEY_EXACT))))
825
796
          goto err;
826
797
      }
831
802
          that matches, is updated. If update causes a conflict again,
832
803
          an error is returned
833
804
        */
834
 
        assert(table->insert_values.size());
 
805
        assert(table->insert_values != NULL);
835
806
        table->storeRecordAsInsert();
836
807
        table->restoreRecord();
837
808
        assert(info->update_fields->elements ==
846
817
          table->cursor->adjust_next_insert_id_after_explicit_value(
847
818
            table->next_number_field->val_int());
848
819
        info->touched++;
849
 
 
850
 
        if (! table->records_are_comparable() || table->compare_records())
 
820
        if ((table->cursor->getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ) &&
 
821
             !bitmap_is_subset(table->write_set, table->read_set)) ||
 
822
            table->compare_record())
851
823
        {
852
 
          if ((error=table->cursor->updateRecord(table->getUpdateRecord(),
853
 
                                                table->getInsertRecord())) &&
 
824
          if ((error=table->cursor->updateRecord(table->record[1],
 
825
                                                table->record[0])) &&
854
826
              error != HA_ERR_RECORD_IS_THE_SAME)
855
827
          {
856
828
            if (info->ignore &&
904
876
            (table->timestamp_field_type == TIMESTAMP_NO_AUTO_SET ||
905
877
             table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH))
906
878
        {
907
 
          if ((error=table->cursor->updateRecord(table->getUpdateRecord(),
908
 
                                                table->getInsertRecord())) &&
 
879
          if ((error=table->cursor->updateRecord(table->record[1],
 
880
                                                table->record[0])) &&
909
881
              error != HA_ERR_RECORD_IS_THE_SAME)
910
882
            goto err;
911
883
          if (error != HA_ERR_RECORD_IS_THE_SAME)
921
893
        }
922
894
        else
923
895
        {
924
 
          if ((error=table->cursor->deleteRecord(table->getUpdateRecord())))
 
896
          if ((error=table->cursor->deleteRecord(table->record[1])))
925
897
            goto err;
926
898
          info->deleted++;
927
899
          if (!table->cursor->has_transactions())
937
909
    */
938
910
    if (table->read_set != save_read_set ||
939
911
        table->write_set != save_write_set)
940
 
      table->column_bitmaps_set(*save_read_set, *save_write_set);
 
912
      table->column_bitmaps_set(save_read_set, save_write_set);
941
913
  }
942
 
  else if ((error=table->cursor->insertRecord(table->getInsertRecord())))
 
914
  else if ((error=table->cursor->insertRecord(table->record[0])))
943
915
  {
944
916
    if (!info->ignore ||
945
917
        table->cursor->is_fatal_error(error, HA_CHECK_DUP))
953
925
  session->record_first_successful_insert_id_in_cur_stmt(table->cursor->insert_id_for_cur_row);
954
926
 
955
927
gok_or_after_err:
 
928
  if (key)
 
929
    free(key);
956
930
  if (!table->cursor->has_transactions())
957
931
    session->transaction.stmt.markModifiedNonTransData();
958
932
  return(0);
966
940
 
967
941
before_err:
968
942
  table->cursor->restore_auto_increment(prev_insert_id);
969
 
  table->column_bitmaps_set(*save_read_set, *save_write_set);
970
 
  return 1;
 
943
  if (key)
 
944
    free(key);
 
945
  table->column_bitmaps_set(save_read_set, save_write_set);
 
946
  return(1);
971
947
}
972
948
 
973
949
 
980
956
{
981
957
  int err= 0;
982
958
 
983
 
  for (Field **field=entry->getFields() ; *field ; field++)
 
959
  for (Field **field=entry->field ; *field ; field++)
984
960
  {
985
961
    if (((*field)->isWriteSet()) == false)
986
962
    {
1068
1044
                             List<Item> *update_fields,
1069
1045
                             List<Item> *update_values,
1070
1046
                             enum_duplicates duplic,
1071
 
                             bool ignore_check_option_errors) :
1072
 
  table_list(table_list_par), table(table_par), fields(fields_par),
1073
 
  autoinc_value_of_last_inserted_row(0),
1074
 
  insert_into_view(table_list_par && 0 != 0)
 
1047
                             bool ignore_check_option_errors)
 
1048
  :table_list(table_list_par), table(table_par), fields(fields_par),
 
1049
   autoinc_value_of_last_inserted_row(0),
 
1050
   insert_into_view(table_list_par && 0 != 0)
1075
1051
{
 
1052
  memset(&info, 0, sizeof(info));
1076
1053
  info.handle_duplicates= duplic;
1077
1054
  info.ignore= ignore_check_option_errors;
1078
1055
  info.update_fields= update_fields;
1322
1299
  if (fields->elements)
1323
1300
    fill_record(session, *fields, values, true);
1324
1301
  else
1325
 
    fill_record(session, table->getFields(), values, true);
 
1302
    fill_record(session, table->field, values, true);
1326
1303
}
1327
1304
 
1328
1305
void select_insert::send_error(uint32_t errcode,const char *err)
1382
1359
     (info.copied ? autoinc_value_of_last_inserted_row : 0));
1383
1360
  session->my_ok((ulong) session->row_count_func,
1384
1361
                 info.copied + info.deleted + info.touched, id, buff);
1385
 
  session->status_var.inserted_row_count+= session->row_count_func; 
1386
1362
  DRIZZLE_INSERT_SELECT_DONE(0, session->row_count_func);
1387
1363
  return 0;
1388
1364
}
1452
1428
      items        in     List of items which should be used to produce rest
1453
1429
                          of fields for the table (corresponding fields will
1454
1430
                          be added to the end of alter_info->create_list)
1455
 
      lock         out    Pointer to the DrizzleLock object for table created
 
1431
      lock         out    Pointer to the DRIZZLE_LOCK object for table created
1456
1432
                          (or open temporary table) will be returned in this
1457
1433
                          parameter. Since this table is not included in
1458
1434
                          Session::lock caller is responsible for explicitly
1484
1460
                                      AlterInfo *alter_info,
1485
1461
                                      List<Item> *items,
1486
1462
                                      bool is_if_not_exists,
1487
 
                                      DrizzleLock **lock,
 
1463
                                      DRIZZLE_LOCK **lock,
1488
1464
                                      TableIdentifier &identifier)
1489
1465
{
1490
 
  TableShare share(message::Table::INTERNAL);
 
1466
  Table tmp_table;              // Used during 'CreateField()'
 
1467
  TableShare share;
 
1468
  Table *table= 0;
1491
1469
  uint32_t select_field_count= items->elements;
1492
1470
  /* Add selected items to field list */
1493
1471
  List_iterator_fast<Item> it(*items);
1503
1481
      create_info->table_existed= 1;            // Mark that table existed
1504
1482
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1505
1483
                          ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
1506
 
                          create_table->getTableName());
 
1484
                          create_table->table_name);
1507
1485
      return create_table->table;
1508
1486
    }
1509
1487
 
1510
 
    my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->getTableName());
 
1488
    my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->table_name);
1511
1489
    return NULL;
1512
1490
  }
1513
1491
 
 
1492
  tmp_table.alias= 0;
 
1493
  tmp_table.timestamp_field= 0;
 
1494
  tmp_table.setShare(&share);
 
1495
 
 
1496
  tmp_table.getMutableShare()->db_create_options= 0;
 
1497
  tmp_table.getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
 
1498
 
 
1499
  if (not table_proto.engine().name().compare("MyISAM"))
 
1500
    tmp_table.getMutableShare()->db_low_byte_first= true;
 
1501
  else if (not table_proto.engine().name().compare("MEMORY"))
 
1502
    tmp_table.getMutableShare()->db_low_byte_first= true;
 
1503
 
 
1504
  tmp_table.null_row= false;
 
1505
  tmp_table.maybe_null= false;
 
1506
 
 
1507
  while ((item=it++))
1514
1508
  {
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
 
      }
 
1509
    CreateField *cr_field;
 
1510
    Field *field, *def_field;
 
1511
    if (item->type() == Item::FUNC_ITEM)
 
1512
      if (item->result_type() != STRING_RESULT)
 
1513
        field= item->tmp_table_field(&tmp_table);
1546
1514
      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
 
    }
 
1515
        field= item->tmp_table_field_from_field_type(&tmp_table, 0);
 
1516
    else
 
1517
      field= create_tmp_field(session, &tmp_table, item, item->type(),
 
1518
                              (Item ***) 0, &tmp_field, &def_field, false,
 
1519
                              false, false, 0);
 
1520
    if (!field ||
 
1521
        !(cr_field=new CreateField(field,(item->type() == Item::FIELD_ITEM ?
 
1522
                                           ((Item_field *)item)->field :
 
1523
                                           (Field*) 0))))
 
1524
      return NULL;
 
1525
    if (item->maybe_null)
 
1526
      cr_field->flags &= ~NOT_NULL_FLAG;
 
1527
    alter_info->create_list.push_back(cr_field);
1568
1528
  }
1569
1529
 
1570
1530
  /*
1574
1534
    creating base table on which name we have exclusive lock. So code below
1575
1535
    should not cause deadlocks or races.
1576
1536
  */
1577
 
  Table *table= 0;
1578
1537
  {
1579
1538
    if (not mysql_create_table_no_lock(session,
1580
1539
                                       identifier,
1592
1551
          or it was created via different mysqld front-end to the
1593
1552
          cluster. We don't have much options but throw an error.
1594
1553
        */
1595
 
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->getTableName());
 
1554
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->table_name);
1596
1555
        return NULL;
1597
1556
      }
1598
1557
 
1599
1558
      if (not identifier.isTmp())
1600
1559
      {
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)
 
1560
        pthread_mutex_lock(&LOCK_open); /* CREATE TABLE... has found that the table already exists for insert and is adapting to use it */
 
1561
        if (session->reopen_name_locked_table(create_table, false))
1605
1562
        {
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
 
          }
 
1563
          quick_rm_table(*session, identifier);
1616
1564
        }
1617
1565
        else
1618
 
        {
1619
 
          plugin::StorageEngine::dropTable(*session, identifier);
1620
 
        }
 
1566
          table= create_table->table;
 
1567
        pthread_mutex_unlock(&LOCK_open);
1621
1568
      }
1622
1569
      else
1623
1570
      {
1630
1577
            it preparable for open. But let us do close_temporary_table() here
1631
1578
            just in case.
1632
1579
          */
1633
 
          session->drop_temporary_table(identifier);
 
1580
          session->drop_temporary_table(create_table);
1634
1581
        }
1635
1582
      }
1636
1583
    }
1637
 
    if (not table)                                   // open failed
 
1584
    if (!table)                                   // open failed
1638
1585
      return NULL;
1639
1586
  }
1640
1587
 
1641
1588
  table->reginfo.lock_type=TL_WRITE;
1642
 
  if (! ((*lock)= session->lockTables(&table, 1, DRIZZLE_LOCK_IGNORE_FLUSH, &not_used)))
 
1589
  if (! ((*lock)= mysql_lock_tables(session, &table, 1,
 
1590
                                    DRIZZLE_LOCK_IGNORE_FLUSH, &not_used)))
1643
1591
  {
1644
1592
    if (*lock)
1645
1593
    {
1646
 
      session->unlockTables(*lock);
 
1594
      mysql_unlock_tables(session, *lock);
1647
1595
      *lock= 0;
1648
1596
    }
1649
1597
 
1659
1607
int
1660
1608
select_create::prepare(List<Item> &values, Select_Lex_Unit *u)
1661
1609
{
1662
 
  DrizzleLock *extra_lock= NULL;
 
1610
  DRIZZLE_LOCK *extra_lock= NULL;
1663
1611
  /*
1664
1612
    For replication, the CREATE-SELECT statement is written
1665
1613
    in two pieces: the first transaction messsage contains 
1677
1625
                                          alter_info, &values,
1678
1626
                                          is_if_not_exists,
1679
1627
                                          &extra_lock, identifier)))
1680
 
  {
1681
1628
    return(-1);                         // abort() deletes table
1682
 
  }
1683
1629
 
1684
1630
  if (extra_lock)
1685
1631
  {
1700
1646
  }
1701
1647
 
1702
1648
 /* First field to copy */
1703
 
  field= table->getFields() + table->getShare()->sizeFields() - values.elements;
 
1649
  field= table->field+table->getShare()->sizeFields() - values.elements;
1704
1650
 
1705
1651
  /* Mark all fields that are given values */
1706
1652
  for (Field **f= field ; *f ; f++)
1707
 
  {
1708
 
    table->setWriteSet((*f)->position());
1709
 
  }
 
1653
    table->setWriteSet((*f)->field_index);
1710
1654
 
1711
1655
  /* Don't set timestamp if used */
1712
1656
  table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
1766
1710
      tables.  This can fail, but we should unlock the table
1767
1711
      nevertheless.
1768
1712
    */
1769
 
    if (!table->getShare()->getType())
 
1713
    if (!table->getShare()->tmp_table)
1770
1714
    {
1771
1715
      TransactionServices &transaction_services= TransactionServices::singleton();
1772
1716
      transaction_services.autocommitOrRollback(session, 0);
1777
1721
    table->cursor->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
1778
1722
    if (m_plock)
1779
1723
    {
1780
 
      session->unlockTables(*m_plock);
 
1724
      mysql_unlock_tables(session, *m_plock);
1781
1725
      *m_plock= NULL;
1782
1726
      m_plock= NULL;
1783
1727
    }
1807
1751
 
1808
1752
  if (m_plock)
1809
1753
  {
1810
 
    session->unlockTables(*m_plock);
 
1754
    mysql_unlock_tables(session, *m_plock);
1811
1755
    *m_plock= NULL;
1812
1756
    m_plock= NULL;
1813
1757
  }