~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_insert.cc

  • Committer: Eric Herman
  • Date: 2008-12-06 19:42:46 UTC
  • mto: (656.1.6 devel)
  • mto: This revision was merged to the branch mainline in revision 665.
  • Revision ID: eric@mysql.com-20081206194246-5cdexuu81i366eek
removed trailing whitespace with simple script:

for file in $(find . -name "*.c") $(find . -name "*.cc") $(find . -name "*.h"); do ruby -pe 'gsub(/\s+$/, $/)' < $file > $file.out; mv $file.out $file; done;

Show diffs side-by-side

added added

removed removed

Lines of Context:
258
258
  Name_resolution_context_state ctx_state;
259
259
  thr_lock_type lock_type;
260
260
  Item *unused_conds= 0;
261
 
  
 
261
 
262
262
 
263
263
  /*
264
264
    Upgrade lock type if the requested lock is incompatible with
334
334
      goto abort;
335
335
  }
336
336
  its.rewind ();
337
 
 
 
337
 
338
338
  /* Restore the current context. */
339
339
  ctx_state.restore_state(context, table_list);
340
340
 
488
488
        A query which per-row-loop can not be interrupted with
489
489
        KILLED, like INSERT, and that does not invoke stored
490
490
        routines can be binlogged with neglecting the KILLED error.
491
 
        
 
491
 
492
492
        If there was no error (error == zero) until after the end of
493
493
        inserting loop the KILLED flag that appeared later can be
494
494
        disregarded since previously possible invocation of stored
508
508
      if (session->transaction.stmt.modified_non_trans_table)
509
509
        session->transaction.all.modified_non_trans_table= true;
510
510
    }
511
 
    assert(transactional_table || !changed || 
 
511
    assert(transactional_table || !changed ||
512
512
                session->transaction.stmt.modified_non_trans_table);
513
513
 
514
514
  }
594
594
                                             List<Item> &fields __attribute__((unused)),
595
595
                                             bool select_insert)
596
596
{
597
 
  
 
597
 
598
598
 
599
599
  /*
600
600
     first table in list is the one we'll INSERT into, requires INSERT_ACL.
622
622
    session                     Thread handler
623
623
    table_list          Global/local table list
624
624
    table               Table to insert into (can be NULL if table should
625
 
                        be taken from table_list->table)    
 
625
                        be taken from table_list->table)
626
626
    where               Where clause (for insert ... select)
627
627
    select_insert       true if INSERT ... SELECT statement
628
 
    check_fields        true if need to check that all INSERT fields are 
 
628
    check_fields        true if need to check that all INSERT fields are
629
629
                        given values.
630
 
    abort_on_warning    whether to report if some INSERT field is not 
 
630
    abort_on_warning    whether to report if some INSERT field is not
631
631
                        assigned as an error (true) or as a warning (false).
632
632
 
633
633
  TODO (in far future)
639
639
  WARNING
640
640
    You MUST set table->insert_values to 0 after calling this function
641
641
    before releasing the table object.
642
 
  
 
642
 
643
643
  RETURN VALUE
644
644
    false OK
645
645
    true  error
659
659
  bool insert_into_view= (0 != 0);
660
660
  bool res= 0;
661
661
  table_map map= 0;
662
 
  
 
662
 
663
663
  /* INSERT should have a SELECT or VALUES clause */
664
664
  assert (!select_insert || !values);
665
665
 
718
718
    {
719
719
      bool saved_abort_on_warning= session->abort_on_warning;
720
720
      session->abort_on_warning= abort_on_warning;
721
 
      res= check_that_all_fields_are_given_values(session, 
722
 
                                                  table ? table : 
 
721
      res= check_that_all_fields_are_given_values(session,
 
722
                                                  table ? table :
723
723
                                                  context->table_list->table,
724
724
                                                  context->table_list);
725
725
      session->abort_on_warning= saved_abort_on_warning;
803
803
  MY_BITMAP *save_read_set, *save_write_set;
804
804
  uint64_t prev_insert_id= table->file->next_insert_id;
805
805
  uint64_t insert_id_for_cur_row= 0;
806
 
  
 
806
 
807
807
 
808
808
  info->records++;
809
809
  save_read_set=  table->read_set;
953
953
          an INSERT or DELETE(s) + INSERT; FOREIGN KEY checks in
954
954
          InnoDB do not function in the defined way if we allow MySQL
955
955
          to convert the latter operation internally to an UPDATE.
956
 
          We also should not perform this conversion if we have 
 
956
          We also should not perform this conversion if we have
957
957
          timestamp field with ON UPDATE which is different from DEFAULT.
958
958
          Another case when conversion should not be performed is when
959
959
          we have ON DELETE trigger on table so user may notice that
1028
1028
  if (session->lex->current_select)
1029
1029
    session->lex->current_select->no_error= 0;        // Give error
1030
1030
  table->file->print_error(error,MYF(0));
1031
 
  
 
1031
 
1032
1032
before_err:
1033
1033
  table->file->restore_auto_increment(prev_insert_id);
1034
1034
  if (key)
1093
1093
{
1094
1094
  LEX *lex= session->lex;
1095
1095
  SELECT_LEX *select_lex= &lex->select_lex;
1096
 
  
 
1096
 
1097
1097
  /*
1098
1098
    SELECT_LEX do not belong to INSERT statement, so we can't add WHERE
1099
1099
    clause if table is VIEW
1100
1100
  */
1101
 
  
 
1101
 
1102
1102
  if (mysql_prepare_insert(session, lex->query_tables,
1103
1103
                           lex->query_tables->table, lex->field_list, 0,
1104
1104
                           lex->update_list, lex->value_list,
1143
1143
  int res;
1144
1144
  table_map map= 0;
1145
1145
  SELECT_LEX *lex_current_select_save= lex->current_select;
1146
 
  
 
1146
 
1147
1147
 
1148
1148
  unit= u;
1149
1149
 
1161
1161
  {
1162
1162
    bool saved_abort_on_warning= session->abort_on_warning;
1163
1163
    session->abort_on_warning= !info.ignore;
1164
 
    res= check_that_all_fields_are_given_values(session, table_list->table, 
 
1164
    res= check_that_all_fields_are_given_values(session, table_list->table,
1165
1165
                                                table_list);
1166
1166
    session->abort_on_warning= saved_abort_on_warning;
1167
1167
  }
1181
1181
    res= res || check_update_fields(session, context->table_list,
1182
1182
                                    *info.update_fields, &map);
1183
1183
    /*
1184
 
      When we are not using GROUP BY and there are no ungrouped aggregate functions 
 
1184
      When we are not using GROUP BY and there are no ungrouped aggregate functions
1185
1185
      we can refer to other tables in the ON DUPLICATE KEY part.
1186
1186
      We use next_name_resolution_table descructively, so check it first (views?)
1187
1187
    */
1192
1192
        We must make a single context out of the two separate name resolution contexts :
1193
1193
        the INSERT table and the tables in the SELECT part of INSERT ... SELECT.
1194
1194
        To do that we must concatenate the two lists
1195
 
      */  
1196
 
      table_list->next_name_resolution_table= 
 
1195
      */
 
1196
      table_list->next_name_resolution_table=
1197
1197
        ctx_state.get_first_name_resolution_table();
1198
1198
 
1199
1199
    res= res || setup_fields(session, 0, *info.update_values,
1242
1242
  else if (!(lex->current_select->options & OPTION_BUFFER_RESULT))
1243
1243
  {
1244
1244
    /*
1245
 
      We must not yet prepare the result table if it is the same as one of the 
1246
 
      source tables (INSERT SELECT). The preparation may disable 
 
1245
      We must not yet prepare the result table if it is the same as one of the
 
1246
      source tables (INSERT SELECT). The preparation may disable
1247
1247
      indexes on the result table, which may be used during the select, if it
1248
1248
      is the same table (Bug #6034). Do the preparation after the select phase
1249
1249
      in select_insert::prepare2().
1287
1287
    If the result table is the same as one of the source tables (INSERT SELECT),
1288
1288
    the result table is not finally prepared at the join prepair phase.
1289
1289
    Do the final preparation now.
1290
 
                       
 
1290
 
1291
1291
  RETURN
1292
1292
    0   OK
1293
1293
*/
1294
1294
 
1295
1295
int select_insert::prepare2(void)
1296
1296
{
1297
 
  
 
1297
 
1298
1298
  if (session->lex->current_select->options & OPTION_BUFFER_RESULT)
1299
1299
    table->file->ha_start_bulk_insert((ha_rows) 0);
1300
1300
  return(0);
1309
1309
 
1310
1310
select_insert::~select_insert()
1311
1311
{
1312
 
  
 
1312
 
1313
1313
  if (table)
1314
1314
  {
1315
1315
    table->next_number_field=0;
1324
1324
 
1325
1325
bool select_insert::send_data(List<Item> &values)
1326
1326
{
1327
 
  
 
1327
 
1328
1328
  bool error=0;
1329
1329
 
1330
1330
  if (unit->offset_limit_cnt)
1340
1340
    return(1);
1341
1341
 
1342
1342
  error= write_record(session, table, &info);
1343
 
    
 
1343
 
1344
1344
  if (!error)
1345
1345
  {
1346
1346
    if (info.handle_duplicates == DUP_UPDATE)
1348
1348
      /*
1349
1349
        Restore fields of the record since it is possible that they were
1350
1350
        changed by ON DUPLICATE KEY UPDATE clause.
1351
 
    
 
1351
 
1352
1352
        If triggers exist then whey can modify some fields which were not
1353
1353
        originally touched by INSERT ... SELECT, so we have to restore
1354
1354
        their original values for the next row.
1362
1362
        value we just saw, we may need to send it to client in the end.
1363
1363
      */
1364
1364
      if (session->first_successful_insert_id_in_cur_stmt == 0) // optimization
1365
 
        autoinc_value_of_last_inserted_row= 
 
1365
        autoinc_value_of_last_inserted_row=
1366
1366
          table->next_number_field->val_int();
1367
1367
      /*
1368
1368
        Clear auto-increment field for the next record, if triggers are used
1385
1385
 
1386
1386
void select_insert::send_error(uint32_t errcode,const char *err)
1387
1387
{
1388
 
  
 
1388
 
1389
1389
 
1390
1390
  my_message(errcode, err, MYF(0));
1391
1391
 
1400
1400
  uint64_t id;
1401
1401
  bool changed;
1402
1402
  Session::killed_state killed_status= session->killed;
1403
 
  
 
1403
 
1404
1404
  error= table->file->ha_end_bulk_insert();
1405
1405
  table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
1406
1406
  table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
1414
1414
    if (session->transaction.stmt.modified_non_trans_table)
1415
1415
      session->transaction.all.modified_non_trans_table= true;
1416
1416
  }
1417
 
  assert(trans_table || !changed || 
 
1417
  assert(trans_table || !changed ||
1418
1418
              session->transaction.stmt.modified_non_trans_table);
1419
1419
 
1420
1420
  /*
1460
1460
 
1461
1461
void select_insert::abort() {
1462
1462
 
1463
 
  
 
1463
 
1464
1464
  /*
1465
1465
    If the creation of the table failed (due to a syntax error, for
1466
1466
    example), no table will have been opened and therefore 'table'
1591
1591
 
1592
1592
  tmp_table.s->db_create_options=0;
1593
1593
  tmp_table.s->blob_ptr_size= portable_sizeof_char_ptr;
1594
 
  tmp_table.s->db_low_byte_first= 
 
1594
  tmp_table.s->db_low_byte_first=
1595
1595
        test(create_info->db_type == myisam_hton ||
1596
1596
             create_info->db_type == heap_hton);
1597
1597
  tmp_table.null_row= false;
1712
1712
select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
1713
1713
{
1714
1714
  DRIZZLE_LOCK *extra_lock= NULL;
1715
 
  
 
1715
 
1716
1716
 
1717
1717
  Tableop_hooks *hook_ptr= NULL;
1718
1718
  /*
1747
1747
    {
1748
1748
      Table const *const table = *tables;
1749
1749
      if (drizzle_bin_log.is_open()
1750
 
          && !table->s->tmp_table 
 
1750
          && !table->s->tmp_table
1751
1751
          && !ptr->get_create_info()->table_existed)
1752
1752
      {
1753
1753
        ptr->binlog_show_create_table(tables, count);
1769
1769
    row-based replication for the statement.  If we are creating a
1770
1770
    temporary table, we need to start a statement transaction.
1771
1771
  */
1772
 
  if ((session->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0 
 
1772
  if ((session->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0
1773
1773
      && drizzle_bin_log.is_open())
1774
1774
  {
1775
1775
    session->binlog_start_trans_and_stmt();
1874
1874
 
1875
1875
void select_create::send_error(uint32_t errcode,const char *err)
1876
1876
{
1877
 
  
 
1877
 
1878
1878
 
1879
1879
  /*
1880
1880
    This will execute any rollbacks that are necessary before writing
1928
1928
 
1929
1929
void select_create::abort()
1930
1930
{
1931
 
  
 
1931
 
1932
1932
 
1933
1933
  /*
1934
1934
    In select_insert::abort() we roll back the statement, including