~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_insert.cc

  • Committer: Brian Aker
  • Date: 2008-10-20 04:28:21 UTC
  • mto: (492.3.21 drizzle-clean-code)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: brian@tangent.org-20081020042821-rqqdrccuu8195k3y
Second pass of thd cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 
46
46
  SYNOPSIS
47
47
    check_insert_fields()
48
 
    thd                         The current thread.
 
48
    session                         The current thread.
49
49
    table                       The table for insert.
50
50
    fields                      The insert fields.
51
51
    values                      The insert values.
61
61
    -1          Error
62
62
*/
63
63
 
64
 
static int check_insert_fields(Session *thd, TableList *table_list,
 
64
static int check_insert_fields(Session *session, TableList *table_list,
65
65
                               List<Item> &fields, List<Item> &values,
66
66
                               bool check_unique,
67
67
                               table_map *map __attribute__((unused)))
85
85
  }
86
86
  else
87
87
  {                                             // Part field list
88
 
    SELECT_LEX *select_lex= &thd->lex->select_lex;
 
88
    SELECT_LEX *select_lex= &session->lex->select_lex;
89
89
    Name_resolution_context *context= &select_lex->context;
90
90
    Name_resolution_context_state ctx_state;
91
91
    int res;
96
96
      return -1;
97
97
    }
98
98
 
99
 
    thd->dup_field= 0;
 
99
    session->dup_field= 0;
100
100
 
101
101
    /* Save the state of the current name resolution context. */
102
102
    ctx_state.save_state(context, table_list);
107
107
    */
108
108
    table_list->next_local= 0;
109
109
    context->resolve_in_table_list_only(table_list);
110
 
    res= setup_fields(thd, 0, fields, MARK_COLUMNS_WRITE, 0, 0);
 
110
    res= setup_fields(session, 0, fields, MARK_COLUMNS_WRITE, 0, 0);
111
111
 
112
112
    /* Restore the current context. */
113
113
    ctx_state.restore_state(context, table_list);
115
115
    if (res)
116
116
      return -1;
117
117
 
118
 
    if (check_unique && thd->dup_field)
 
118
    if (check_unique && session->dup_field)
119
119
    {
120
 
      my_error(ER_FIELD_SPECIFIED_TWICE, MYF(0), thd->dup_field->field_name);
 
120
      my_error(ER_FIELD_SPECIFIED_TWICE, MYF(0), session->dup_field->field_name);
121
121
      return -1;
122
122
    }
123
123
    if (table->timestamp_field) // Don't automaticly set timestamp if used
146
146
 
147
147
  SYNOPSIS
148
148
    check_update_fields()
149
 
    thd                         The current thread.
 
149
    session                         The current thread.
150
150
    insert_table_list           The insert table list.
151
151
    table                       The table for update.
152
152
    update_fields               The update fields.
160
160
    -1          Error
161
161
*/
162
162
 
163
 
static int check_update_fields(Session *thd, TableList *insert_table_list,
 
163
static int check_update_fields(Session *session, TableList *insert_table_list,
164
164
                               List<Item> &update_fields,
165
165
                               table_map *map __attribute__((unused)))
166
166
{
178
178
  }
179
179
 
180
180
  /* Check the fields we are going to modify */
181
 
  if (setup_fields(thd, 0, update_fields, MARK_COLUMNS_WRITE, 0, 0))
 
181
  if (setup_fields(session, 0, update_fields, MARK_COLUMNS_WRITE, 0, 0))
182
182
    return -1;
183
183
 
184
184
  if (table->timestamp_field)
205
205
*/
206
206
 
207
207
static
208
 
void upgrade_lock_type(Session *thd __attribute__((unused)),
 
208
void upgrade_lock_type(Session *session __attribute__((unused)),
209
209
                       thr_lock_type *lock_type,
210
210
                       enum_duplicates duplic,
211
211
                       bool is_multi_insert __attribute__((unused)))
227
227
  end of dispatch_command().
228
228
*/
229
229
 
230
 
bool mysql_insert(Session *thd,TableList *table_list,
 
230
bool mysql_insert(Session *session,TableList *table_list,
231
231
                  List<Item> &fields,
232
232
                  List<List_item> &values_list,
233
233
                  List<Item> &update_fields,
256
256
    Upgrade lock type if the requested lock is incompatible with
257
257
    the current connection mode or table operation.
258
258
  */
259
 
  upgrade_lock_type(thd, &table_list->lock_type, duplic,
 
259
  upgrade_lock_type(session, &table_list->lock_type, duplic,
260
260
                    values_list.elements > 1);
261
261
 
262
262
  /*
265
265
    never be able to get a lock on the table. QQQ: why not
266
266
    upgrade the lock here instead?
267
267
  */
268
 
  if (table_list->lock_type == TL_WRITE_DELAYED && thd->locked_tables &&
269
 
      find_locked_table(thd, table_list->db, table_list->table_name))
 
268
  if (table_list->lock_type == TL_WRITE_DELAYED && session->locked_tables &&
 
269
      find_locked_table(session, table_list->db, table_list->table_name))
270
270
  {
271
271
    my_error(ER_DELAYED_INSERT_TABLE_LOCKED, MYF(0),
272
272
             table_list->table_name);
274
274
  }
275
275
 
276
276
  {
277
 
    if (open_and_lock_tables(thd, table_list))
 
277
    if (open_and_lock_tables(session, table_list))
278
278
      return(true);
279
279
  }
280
280
  lock_type= table_list->lock_type;
281
281
 
282
 
  thd->set_proc_info("init");
283
 
  thd->used_tables=0;
 
282
  session->set_proc_info("init");
 
283
  session->used_tables=0;
284
284
  values= its++;
285
285
  value_count= values->elements;
286
286
 
287
 
  if (mysql_prepare_insert(thd, table_list, table, fields, values,
 
287
  if (mysql_prepare_insert(session, table_list, table, fields, values,
288
288
                           update_fields, update_values, duplic, &unused_conds,
289
289
                           false,
290
290
                           (fields.elements || !value_count ||
294
294
  /* mysql_prepare_insert set table_list->table if it was not set */
295
295
  table= table_list->table;
296
296
 
297
 
  context= &thd->lex->select_lex.context;
 
297
  context= &session->lex->select_lex.context;
298
298
  /*
299
299
    These three asserts test the hypothesis that the resetting of the name
300
300
    resolution context below is not necessary at all since the list of local
322
322
      my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter);
323
323
      goto abort;
324
324
    }
325
 
    if (setup_fields(thd, 0, *values, MARK_COLUMNS_READ, 0, 0))
 
325
    if (setup_fields(session, 0, *values, MARK_COLUMNS_READ, 0, 0))
326
326
      goto abort;
327
327
  }
328
328
  its.rewind ();
344
344
    For single line insert, generate an error if try to set a NOT NULL field
345
345
    to NULL.
346
346
  */
347
 
  thd->count_cuted_fields= ((values_list.elements == 1 &&
 
347
  session->count_cuted_fields= ((values_list.elements == 1 &&
348
348
                             !ignore) ?
349
349
                            CHECK_FIELD_ERROR_FOR_NULL :
350
350
                            CHECK_FIELD_WARN);
351
 
  thd->cuted_fields = 0L;
 
351
  session->cuted_fields = 0L;
352
352
  table->next_number_field=table->found_next_number_field;
353
353
 
354
 
  if (thd->slave_thread &&
 
354
  if (session->slave_thread &&
355
355
      (info.handle_duplicates == DUP_UPDATE) &&
356
356
      (table->next_number_field != NULL) &&
357
357
      rpl_master_has_bug(&active_mi->rli, 24432))
358
358
    goto abort;
359
359
 
360
360
  error=0;
361
 
  thd->set_proc_info("update");
 
361
  session->set_proc_info("update");
362
362
  if (duplic == DUP_REPLACE)
363
363
    table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE);
364
364
  if (duplic == DUP_UPDATE)
370
370
  }
371
371
 
372
372
 
373
 
  thd->abort_on_warning= !ignore;
 
373
  session->abort_on_warning= !ignore;
374
374
 
375
375
  table->mark_columns_needed_for_insert();
376
376
 
379
379
    if (fields.elements || !value_count)
380
380
    {
381
381
      restore_record(table,s->default_values);  // Get empty record
382
 
      if (fill_record(thd, fields, *values, 0))
 
382
      if (fill_record(session, fields, *values, 0))
383
383
      {
384
 
        if (values_list.elements != 1 && ! thd->is_error())
 
384
        if (values_list.elements != 1 && ! session->is_error())
385
385
        {
386
386
          info.records++;
387
387
          continue;
388
388
        }
389
389
        /*
390
 
          TODO: set thd->abort_on_warning if values_list.elements == 1
 
390
          TODO: set session->abort_on_warning if values_list.elements == 1
391
391
          and check that all items return warning in case of problem with
392
392
          storing field.
393
393
        */
397
397
    }
398
398
    else
399
399
    {
400
 
      if (thd->used_tables)                     // Column used in values()
 
400
      if (session->used_tables)                 // Column used in values()
401
401
        restore_record(table,s->default_values);        // Get empty record
402
402
      else
403
403
      {
408
408
        */
409
409
        table->record[0][0]= table->s->default_values[0];
410
410
      }
411
 
      if (fill_record(thd, table->field, *values, 0))
 
411
      if (fill_record(session, table->field, *values, 0))
412
412
      {
413
 
        if (values_list.elements != 1 && ! thd->is_error())
 
413
        if (values_list.elements != 1 && ! session->is_error())
414
414
        {
415
415
          info.records++;
416
416
          continue;
420
420
      }
421
421
    }
422
422
 
423
 
    error=write_record(thd, table ,&info);
 
423
    error=write_record(session, table ,&info);
424
424
    if (error)
425
425
      break;
426
 
    thd->row_count++;
 
426
    session->row_count++;
427
427
  }
428
428
 
429
 
  free_underlaid_joins(thd, &thd->lex->select_lex);
 
429
  free_underlaid_joins(session, &session->lex->select_lex);
430
430
  joins_freed= true;
431
431
 
432
432
  /*
457
457
        before binlog writing and ha_autocommit_or_rollback
458
458
      */
459
459
    }
460
 
    if ((changed && error <= 0) || thd->transaction.stmt.modified_non_trans_table || was_insert_delayed)
 
460
    if ((changed && error <= 0) || session->transaction.stmt.modified_non_trans_table || was_insert_delayed)
461
461
    {
462
462
      if (mysql_bin_log.is_open())
463
463
      {
465
465
        {
466
466
          /*
467
467
            [Guilhem wrote] Temporary errors may have filled
468
 
            thd->net.last_error/errno.  For example if there has
 
468
            session->net.last_error/errno.  For example if there has
469
469
            been a disk full error when writing the row, and it was
470
 
            MyISAM, then thd->net.last_error/errno will be set to
 
470
            MyISAM, then session->net.last_error/errno will be set to
471
471
            "disk full"... and the my_pwrite() will wait until free
472
472
            space appears, and so when it finishes then the
473
473
            write_row() was entirely successful
474
474
          */
475
475
          /* todo: consider removing */
476
 
          thd->clear_error();
 
476
          session->clear_error();
477
477
        }
478
478
        /* bug#22725:
479
479
 
487
487
        routines did not result in any error due to the KILLED.  In
488
488
        such case the flag is ignored for constructing binlog event.
489
489
        */
490
 
        assert(thd->killed != Session::KILL_BAD_DATA || error > 0);
491
 
        if (thd->binlog_query(Session::ROW_QUERY_TYPE,
492
 
                              thd->query, thd->query_length,
 
490
        assert(session->killed != Session::KILL_BAD_DATA || error > 0);
 
491
        if (session->binlog_query(Session::ROW_QUERY_TYPE,
 
492
                              session->query, session->query_length,
493
493
                              transactional_table, false,
494
 
                              (error>0) ? thd->killed : Session::NOT_KILLED) &&
 
494
                              (error>0) ? session->killed : Session::NOT_KILLED) &&
495
495
            transactional_table)
496
496
        {
497
497
          error=1;
498
498
        }
499
499
      }
500
 
      if (thd->transaction.stmt.modified_non_trans_table)
501
 
        thd->transaction.all.modified_non_trans_table= true;
 
500
      if (session->transaction.stmt.modified_non_trans_table)
 
501
        session->transaction.all.modified_non_trans_table= true;
502
502
    }
503
503
    assert(transactional_table || !changed || 
504
 
                thd->transaction.stmt.modified_non_trans_table);
 
504
                session->transaction.stmt.modified_non_trans_table);
505
505
 
506
506
  }
507
 
  thd->set_proc_info("end");
 
507
  session->set_proc_info("end");
508
508
  /*
509
509
    We'll report to the client this id:
510
510
    - if the table contains an autoincrement column and we successfully
515
515
    inserted, the id of the last "inserted" row (if IGNORE, that value may not
516
516
    have been really inserted but ignored).
517
517
  */
518
 
  id= (thd->first_successful_insert_id_in_cur_stmt > 0) ?
519
 
    thd->first_successful_insert_id_in_cur_stmt :
520
 
    (thd->arg_of_last_insert_id_function ?
521
 
     thd->first_successful_insert_id_in_prev_stmt :
 
518
  id= (session->first_successful_insert_id_in_cur_stmt > 0) ?
 
519
    session->first_successful_insert_id_in_cur_stmt :
 
520
    (session->arg_of_last_insert_id_function ?
 
521
     session->first_successful_insert_id_in_prev_stmt :
522
522
     ((table->next_number_field && info.copied) ?
523
523
     table->next_number_field->val_int() : 0));
524
524
  table->next_number_field=0;
525
 
  thd->count_cuted_fields= CHECK_FIELD_IGNORE;
 
525
  session->count_cuted_fields= CHECK_FIELD_IGNORE;
526
526
  table->auto_increment_field_not_null= false;
527
527
  if (duplic == DUP_REPLACE)
528
528
    table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
529
529
 
530
530
  if (error)
531
531
    goto abort;
532
 
  if (values_list.elements == 1 && (!(thd->options & OPTION_WARNINGS) ||
533
 
                                    !thd->cuted_fields))
 
532
  if (values_list.elements == 1 && (!(session->options & OPTION_WARNINGS) ||
 
533
                                    !session->cuted_fields))
534
534
  {
535
 
    thd->row_count_func= info.copied + info.deleted +
536
 
                         ((thd->client_capabilities & CLIENT_FOUND_ROWS) ?
 
535
    session->row_count_func= info.copied + info.deleted +
 
536
                         ((session->client_capabilities & CLIENT_FOUND_ROWS) ?
537
537
                          info.touched : info.updated);
538
 
    my_ok(thd, (ulong) thd->row_count_func, id);
 
538
    my_ok(session, (ulong) session->row_count_func, id);
539
539
  }
540
540
  else
541
541
  {
542
542
    char buff[160];
543
 
    ha_rows updated=((thd->client_capabilities & CLIENT_FOUND_ROWS) ?
 
543
    ha_rows updated=((session->client_capabilities & CLIENT_FOUND_ROWS) ?
544
544
                     info.touched : info.updated);
545
545
    if (ignore)
546
546
      sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
547
 
              (ulong) (info.records - info.copied), (ulong) thd->cuted_fields);
 
547
              (ulong) (info.records - info.copied), (ulong) session->cuted_fields);
548
548
    else
549
549
      sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
550
 
              (ulong) (info.deleted + updated), (ulong) thd->cuted_fields);
551
 
    thd->row_count_func= info.copied + info.deleted + updated;
552
 
    ::my_ok(thd, (ulong) thd->row_count_func, id, buff);
 
550
              (ulong) (info.deleted + updated), (ulong) session->cuted_fields);
 
551
    session->row_count_func= info.copied + info.deleted + updated;
 
552
    ::my_ok(session, (ulong) session->row_count_func, id, buff);
553
553
  }
554
 
  thd->abort_on_warning= 0;
 
554
  session->abort_on_warning= 0;
555
555
  DRIZZLE_INSERT_END();
556
556
  return(false);
557
557
 
559
559
  if (table != NULL)
560
560
    table->file->ha_release_auto_increment();
561
561
  if (!joins_freed)
562
 
    free_underlaid_joins(thd, &thd->lex->select_lex);
563
 
  thd->abort_on_warning= 0;
 
562
    free_underlaid_joins(session, &session->lex->select_lex);
 
563
  session->abort_on_warning= 0;
564
564
  DRIZZLE_INSERT_END();
565
565
  return(true);
566
566
}
571
571
 
572
572
  SYNOPSIS
573
573
     mysql_prepare_insert_check_table()
574
 
     thd                Thread handle
 
574
     session            Thread handle
575
575
     table_list         Table list
576
576
     fields             List of fields to be updated
577
577
     where              Pointer to where clause
582
582
     true  ERROR
583
583
*/
584
584
 
585
 
static bool mysql_prepare_insert_check_table(Session *thd, TableList *table_list,
 
585
static bool mysql_prepare_insert_check_table(Session *session, TableList *table_list,
586
586
                                             List<Item> &fields __attribute__((unused)),
587
587
                                             bool select_insert)
588
588
{
595
595
     than INSERT.
596
596
  */
597
597
 
598
 
  if (setup_tables_and_check_access(thd, &thd->lex->select_lex.context,
599
 
                                    &thd->lex->select_lex.top_join_list,
 
598
  if (setup_tables_and_check_access(session, &session->lex->select_lex.context,
 
599
                                    &session->lex->select_lex.top_join_list,
600
600
                                    table_list,
601
 
                                    &thd->lex->select_lex.leaf_tables,
 
601
                                    &session->lex->select_lex.leaf_tables,
602
602
                                    select_insert))
603
603
    return(true);
604
604
 
611
611
 
612
612
  SYNOPSIS
613
613
    mysql_prepare_insert()
614
 
    thd                 Thread handler
 
614
    session                     Thread handler
615
615
    table_list          Global/local table list
616
616
    table               Table to insert into (can be NULL if table should
617
617
                        be taken from table_list->table)    
637
637
    true  error
638
638
*/
639
639
 
640
 
bool mysql_prepare_insert(Session *thd, TableList *table_list,
 
640
bool mysql_prepare_insert(Session *session, TableList *table_list,
641
641
                          Table *table, List<Item> &fields, List_item *values,
642
642
                          List<Item> &update_fields, List<Item> &update_values,
643
643
                          enum_duplicates duplic,
645
645
                          bool select_insert,
646
646
                          bool check_fields, bool abort_on_warning)
647
647
{
648
 
  SELECT_LEX *select_lex= &thd->lex->select_lex;
 
648
  SELECT_LEX *select_lex= &session->lex->select_lex;
649
649
  Name_resolution_context *context= &select_lex->context;
650
650
  Name_resolution_context_state ctx_state;
651
651
  bool insert_into_view= (0 != 0);
678
678
  if (duplic == DUP_UPDATE)
679
679
  {
680
680
    /* it should be allocated before Item::fix_fields() */
681
 
    if (table_list->set_insert_values(thd->mem_root))
 
681
    if (table_list->set_insert_values(session->mem_root))
682
682
      return(true);
683
683
  }
684
684
 
685
 
  if (mysql_prepare_insert_check_table(thd, table_list, fields, select_insert))
 
685
  if (mysql_prepare_insert_check_table(session, table_list, fields, select_insert))
686
686
    return(true);
687
687
 
688
688
 
702
702
    table_list->next_local= 0;
703
703
    context->resolve_in_table_list_only(table_list);
704
704
 
705
 
    res= check_insert_fields(thd, context->table_list, fields, *values,
 
705
    res= check_insert_fields(session, context->table_list, fields, *values,
706
706
                             !insert_into_view, &map) ||
707
 
      setup_fields(thd, 0, *values, MARK_COLUMNS_READ, 0, 0);
 
707
      setup_fields(session, 0, *values, MARK_COLUMNS_READ, 0, 0);
708
708
 
709
709
    if (!res && check_fields)
710
710
    {
711
 
      bool saved_abort_on_warning= thd->abort_on_warning;
712
 
      thd->abort_on_warning= abort_on_warning;
713
 
      res= check_that_all_fields_are_given_values(thd, 
 
711
      bool saved_abort_on_warning= session->abort_on_warning;
 
712
      session->abort_on_warning= abort_on_warning;
 
713
      res= check_that_all_fields_are_given_values(session, 
714
714
                                                  table ? table : 
715
715
                                                  context->table_list->table,
716
716
                                                  context->table_list);
717
 
      thd->abort_on_warning= saved_abort_on_warning;
 
717
      session->abort_on_warning= saved_abort_on_warning;
718
718
    }
719
719
 
720
720
    if (!res && duplic == DUP_UPDATE)
721
721
    {
722
 
      res= check_update_fields(thd, context->table_list, update_fields, &map);
 
722
      res= check_update_fields(session, context->table_list, update_fields, &map);
723
723
    }
724
724
 
725
725
    /* Restore the current context. */
726
726
    ctx_state.restore_state(context, table_list);
727
727
 
728
728
    if (!res)
729
 
      res= setup_fields(thd, 0, update_values, MARK_COLUMNS_READ, 0, 0);
 
729
      res= setup_fields(session, 0, update_values, MARK_COLUMNS_READ, 0, 0);
730
730
  }
731
731
 
732
732
  if (res)
738
738
  if (!select_insert)
739
739
  {
740
740
    TableList *duplicate;
741
 
    if ((duplicate= unique_table(thd, table_list, table_list->next_global, 1)))
 
741
    if ((duplicate= unique_table(session, table_list, table_list->next_global, 1)))
742
742
    {
743
743
      update_non_unique_table_error(table_list, "INSERT", duplicate);
744
744
      return(true);
767
767
 
768
768
  SYNOPSIS
769
769
     write_record()
770
 
      thd   - thread context
 
770
      session   - thread context
771
771
      table - table to which record should be written
772
772
      info  - COPY_INFO structure describing handling of duplicates
773
773
              and which is used for counting number of records inserted
779
779
    then both on update triggers will work instead. Similarly both on
780
780
    delete triggers will be invoked if we will delete conflicting records.
781
781
 
782
 
    Sets thd->transaction.stmt.modified_non_trans_table to true if table which is updated didn't have
 
782
    Sets session->transaction.stmt.modified_non_trans_table to true if table which is updated didn't have
783
783
    transactions.
784
784
 
785
785
  RETURN VALUE
788
788
*/
789
789
 
790
790
 
791
 
int write_record(Session *thd, Table *table,COPY_INFO *info)
 
791
int write_record(Session *session, Table *table,COPY_INFO *info)
792
792
{
793
793
  int error;
794
794
  char *key=0;
811
811
        If we do more than one iteration of this loop, from the second one the
812
812
        row will have an explicit value in the autoinc field, which was set at
813
813
        the first call of handler::update_auto_increment(). So we must save
814
 
        the autogenerated value to avoid thd->insert_id_for_cur_row to become
 
814
        the autogenerated value to avoid session->insert_id_for_cur_row to become
815
815
        0.
816
816
      */
817
817
      if (table->file->insert_id_for_cur_row > 0)
890
890
        restore_record(table,record[1]);
891
891
        assert(info->update_fields->elements ==
892
892
                    info->update_values->elements);
893
 
        if (fill_record(thd, *info->update_fields,
 
893
        if (fill_record(session, *info->update_fields,
894
894
                                                 *info->update_values,
895
895
                                                 info->ignore))
896
896
          goto before_err;
967
967
            info->deleted++;
968
968
          else
969
969
            error= 0;
970
 
          thd->record_first_successful_insert_id_in_cur_stmt(table->file->insert_id_for_cur_row);
 
970
          session->record_first_successful_insert_id_in_cur_stmt(table->file->insert_id_for_cur_row);
971
971
          /*
972
972
            Since we pretend that we have done insert we should call
973
973
            its after triggers.
980
980
            goto err;
981
981
          info->deleted++;
982
982
          if (!table->file->has_transactions())
983
 
            thd->transaction.stmt.modified_non_trans_table= true;
 
983
            session->transaction.stmt.modified_non_trans_table= true;
984
984
          /* Let us attempt do write_row() once more */
985
985
        }
986
986
      }
987
987
    }
988
 
    thd->record_first_successful_insert_id_in_cur_stmt(table->file->insert_id_for_cur_row);
 
988
    session->record_first_successful_insert_id_in_cur_stmt(table->file->insert_id_for_cur_row);
989
989
    /*
990
990
      Restore column maps if they where replaced during an duplicate key
991
991
      problem.
1005
1005
 
1006
1006
after_n_copied_inc:
1007
1007
  info->copied++;
1008
 
  thd->record_first_successful_insert_id_in_cur_stmt(table->file->insert_id_for_cur_row);
 
1008
  session->record_first_successful_insert_id_in_cur_stmt(table->file->insert_id_for_cur_row);
1009
1009
 
1010
1010
gok_or_after_err:
1011
1011
  if (key)
1012
1012
    my_safe_afree(key,table->s->max_unique_length,MAX_KEY_LENGTH);
1013
1013
  if (!table->file->has_transactions())
1014
 
    thd->transaction.stmt.modified_non_trans_table= true;
 
1014
    session->transaction.stmt.modified_non_trans_table= true;
1015
1015
  return(0);
1016
1016
 
1017
1017
err:
1018
1018
  info->last_errno= error;
1019
1019
  /* current_select is NULL if this is a delayed insert */
1020
 
  if (thd->lex->current_select)
1021
 
    thd->lex->current_select->no_error= 0;        // Give error
 
1020
  if (session->lex->current_select)
 
1021
    session->lex->current_select->no_error= 0;        // Give error
1022
1022
  table->file->print_error(error,MYF(0));
1023
1023
  
1024
1024
before_err:
1034
1034
  Check that all fields with arn't null_fields are used
1035
1035
******************************************************************************/
1036
1036
 
1037
 
int check_that_all_fields_are_given_values(Session *thd, Table *entry,
 
1037
int check_that_all_fields_are_given_values(Session *session, Table *entry,
1038
1038
                                           TableList *table_list)
1039
1039
{
1040
1040
  int err= 0;
1053
1053
        view= test(0);
1054
1054
      }
1055
1055
      {
1056
 
        push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1056
        push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1057
1057
                            ER_NO_DEFAULT_FOR_FIELD,
1058
1058
                            ER(ER_NO_DEFAULT_FOR_FIELD),
1059
1059
                            (*field)->field_name);
1061
1061
      err= 1;
1062
1062
    }
1063
1063
  }
1064
 
  return thd->abort_on_warning ? err : 0;
 
1064
  return session->abort_on_warning ? err : 0;
1065
1065
}
1066
1066
 
1067
1067
/***************************************************************************
1074
1074
 
1075
1075
  SYNOPSIS
1076
1076
    mysql_insert_select_prepare()
1077
 
    thd         thread handler
 
1077
    session         thread handler
1078
1078
 
1079
1079
  RETURN
1080
1080
    false OK
1081
1081
    true  Error
1082
1082
*/
1083
1083
 
1084
 
bool mysql_insert_select_prepare(Session *thd)
 
1084
bool mysql_insert_select_prepare(Session *session)
1085
1085
{
1086
 
  LEX *lex= thd->lex;
 
1086
  LEX *lex= session->lex;
1087
1087
  SELECT_LEX *select_lex= &lex->select_lex;
1088
1088
  
1089
1089
 
1098
1098
  if (lex->current_select->select_limit)
1099
1099
  {
1100
1100
    lex->set_stmt_unsafe();
1101
 
    thd->set_current_stmt_binlog_row_based_if_mixed();
 
1101
    session->set_current_stmt_binlog_row_based_if_mixed();
1102
1102
  }
1103
1103
  /*
1104
1104
    SELECT_LEX do not belong to INSERT statement, so we can't add WHERE
1105
1105
    clause if table is VIEW
1106
1106
  */
1107
1107
  
1108
 
  if (mysql_prepare_insert(thd, lex->query_tables,
 
1108
  if (mysql_prepare_insert(session, lex->query_tables,
1109
1109
                           lex->query_tables->table, lex->field_list, 0,
1110
1110
                           lex->update_list, lex->value_list,
1111
1111
                           lex->duplicates,
1145
1145
int
1146
1146
select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
1147
1147
{
1148
 
  LEX *lex= thd->lex;
 
1148
  LEX *lex= session->lex;
1149
1149
  int res;
1150
1150
  table_map map= 0;
1151
1151
  SELECT_LEX *lex_current_select_save= lex->current_select;
1159
1159
    we are fixing fields from insert list.
1160
1160
  */
1161
1161
  lex->current_select= &lex->select_lex;
1162
 
  res= check_insert_fields(thd, table_list, *fields, values,
 
1162
  res= check_insert_fields(session, table_list, *fields, values,
1163
1163
                           !insert_into_view, &map) ||
1164
 
       setup_fields(thd, 0, values, MARK_COLUMNS_READ, 0, 0);
 
1164
       setup_fields(session, 0, values, MARK_COLUMNS_READ, 0, 0);
1165
1165
 
1166
1166
  if (!res && fields->elements)
1167
1167
  {
1168
 
    bool saved_abort_on_warning= thd->abort_on_warning;
1169
 
    thd->abort_on_warning= !info.ignore;
1170
 
    res= check_that_all_fields_are_given_values(thd, table_list->table, 
 
1168
    bool saved_abort_on_warning= session->abort_on_warning;
 
1169
    session->abort_on_warning= !info.ignore;
 
1170
    res= check_that_all_fields_are_given_values(session, table_list->table, 
1171
1171
                                                table_list);
1172
 
    thd->abort_on_warning= saved_abort_on_warning;
 
1172
    session->abort_on_warning= saved_abort_on_warning;
1173
1173
  }
1174
1174
 
1175
1175
  if (info.handle_duplicates == DUP_UPDATE && !res)
1184
1184
    table_list->next_local= 0;
1185
1185
    context->resolve_in_table_list_only(table_list);
1186
1186
 
1187
 
    res= res || check_update_fields(thd, context->table_list,
 
1187
    res= res || check_update_fields(session, context->table_list,
1188
1188
                                    *info.update_fields, &map);
1189
1189
    /*
1190
1190
      When we are not using GROUP BY and there are no ungrouped aggregate functions 
1202
1202
      table_list->next_name_resolution_table= 
1203
1203
        ctx_state.get_first_name_resolution_table();
1204
1204
 
1205
 
    res= res || setup_fields(thd, 0, *info.update_values,
 
1205
    res= res || setup_fields(session, 0, *info.update_values,
1206
1206
                             MARK_COLUMNS_READ, 0, 0);
1207
1207
    if (!res)
1208
1208
    {
1239
1239
    Is table which we are changing used somewhere in other parts of
1240
1240
    query
1241
1241
  */
1242
 
  if (unique_table(thd, table_list, table_list->next_global, 0))
 
1242
  if (unique_table(session, table_list, table_list->next_global, 0))
1243
1243
  {
1244
1244
    /* Using same table for INSERT and SELECT */
1245
1245
    lex->current_select->options|= OPTION_BUFFER_RESULT;
1261
1261
  restore_record(table,s->default_values);              // Get empty record
1262
1262
  table->next_number_field=table->found_next_number_field;
1263
1263
 
1264
 
  if (thd->slave_thread &&
 
1264
  if (session->slave_thread &&
1265
1265
      (info.handle_duplicates == DUP_UPDATE) &&
1266
1266
      (table->next_number_field != NULL) &&
1267
1267
      rpl_master_has_bug(&active_mi->rli, 24432))
1268
1268
    return(1);
1269
1269
 
1270
 
  thd->cuted_fields=0;
 
1270
  session->cuted_fields=0;
1271
1271
  if (info.ignore || info.handle_duplicates != DUP_ERROR)
1272
1272
    table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
1273
1273
  if (info.handle_duplicates == DUP_REPLACE)
1274
1274
    table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE);
1275
1275
  if (info.handle_duplicates == DUP_UPDATE)
1276
1276
    table->file->extra(HA_EXTRA_INSERT_WITH_UPDATE);
1277
 
  thd->abort_on_warning= !info.ignore;
 
1277
  session->abort_on_warning= !info.ignore;
1278
1278
  table->mark_columns_needed_for_insert();
1279
1279
 
1280
1280
 
1301
1301
int select_insert::prepare2(void)
1302
1302
{
1303
1303
  
1304
 
  if (thd->lex->current_select->options & OPTION_BUFFER_RESULT)
 
1304
  if (session->lex->current_select->options & OPTION_BUFFER_RESULT)
1305
1305
    table->file->ha_start_bulk_insert((ha_rows) 0);
1306
1306
  return(0);
1307
1307
}
1322
1322
    table->auto_increment_field_not_null= false;
1323
1323
    table->file->ha_reset();
1324
1324
  }
1325
 
  thd->count_cuted_fields= CHECK_FIELD_IGNORE;
1326
 
  thd->abort_on_warning= 0;
 
1325
  session->count_cuted_fields= CHECK_FIELD_IGNORE;
 
1326
  session->abort_on_warning= 0;
1327
1327
  return;
1328
1328
}
1329
1329
 
1339
1339
    return(0);
1340
1340
  }
1341
1341
 
1342
 
  thd->count_cuted_fields= CHECK_FIELD_WARN;    // Calculate cuted fields
 
1342
  session->count_cuted_fields= CHECK_FIELD_WARN;        // Calculate cuted fields
1343
1343
  store_values(values);
1344
 
  thd->count_cuted_fields= CHECK_FIELD_IGNORE;
1345
 
  if (thd->is_error())
 
1344
  session->count_cuted_fields= CHECK_FIELD_IGNORE;
 
1345
  if (session->is_error())
1346
1346
    return(1);
1347
1347
 
1348
 
  error= write_record(thd, table, &info);
 
1348
  error= write_record(session, table, &info);
1349
1349
    
1350
1350
  if (!error)
1351
1351
  {
1367
1367
        If no value has been autogenerated so far, we need to remember the
1368
1368
        value we just saw, we may need to send it to client in the end.
1369
1369
      */
1370
 
      if (thd->first_successful_insert_id_in_cur_stmt == 0) // optimization
 
1370
      if (session->first_successful_insert_id_in_cur_stmt == 0) // optimization
1371
1371
        autoinc_value_of_last_inserted_row= 
1372
1372
          table->next_number_field->val_int();
1373
1373
      /*
1384
1384
void select_insert::store_values(List<Item> &values)
1385
1385
{
1386
1386
  if (fields->elements)
1387
 
    fill_record(thd, *fields, values, 1);
 
1387
    fill_record(session, *fields, values, 1);
1388
1388
  else
1389
 
    fill_record(thd, table->field, values, 1);
 
1389
    fill_record(session, table->field, values, 1);
1390
1390
}
1391
1391
 
1392
1392
void select_insert::send_error(uint32_t errcode,const char *err)
1405
1405
  bool const trans_table= table->file->has_transactions();
1406
1406
  uint64_t id;
1407
1407
  bool changed;
1408
 
  Session::killed_state killed_status= thd->killed;
 
1408
  Session::killed_state killed_status= session->killed;
1409
1409
  
1410
1410
  error= table->file->ha_end_bulk_insert();
1411
1411
  table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
1417
1417
      We must invalidate the table in the query cache before binlog writing
1418
1418
      and ha_autocommit_or_rollback.
1419
1419
    */
1420
 
    if (thd->transaction.stmt.modified_non_trans_table)
1421
 
      thd->transaction.all.modified_non_trans_table= true;
 
1420
    if (session->transaction.stmt.modified_non_trans_table)
 
1421
      session->transaction.all.modified_non_trans_table= true;
1422
1422
  }
1423
1423
  assert(trans_table || !changed || 
1424
 
              thd->transaction.stmt.modified_non_trans_table);
 
1424
              session->transaction.stmt.modified_non_trans_table);
1425
1425
 
1426
1426
  /*
1427
1427
    Write to binlog before commiting transaction.  No statement will
1432
1432
  if (mysql_bin_log.is_open())
1433
1433
  {
1434
1434
    if (!error)
1435
 
      thd->clear_error();
1436
 
    thd->binlog_query(Session::ROW_QUERY_TYPE,
1437
 
                      thd->query, thd->query_length,
 
1435
      session->clear_error();
 
1436
    session->binlog_query(Session::ROW_QUERY_TYPE,
 
1437
                      session->query, session->query_length,
1438
1438
                      trans_table, false, killed_status);
1439
1439
  }
1440
1440
  table->file->ha_release_auto_increment();
1447
1447
  char buff[160];
1448
1448
  if (info.ignore)
1449
1449
    sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
1450
 
            (ulong) (info.records - info.copied), (ulong) thd->cuted_fields);
 
1450
            (ulong) (info.records - info.copied), (ulong) session->cuted_fields);
1451
1451
  else
1452
1452
    sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
1453
 
            (ulong) (info.deleted+info.updated), (ulong) thd->cuted_fields);
1454
 
  thd->row_count_func= info.copied + info.deleted +
1455
 
                       ((thd->client_capabilities & CLIENT_FOUND_ROWS) ?
 
1453
            (ulong) (info.deleted+info.updated), (ulong) session->cuted_fields);
 
1454
  session->row_count_func= info.copied + info.deleted +
 
1455
                       ((session->client_capabilities & CLIENT_FOUND_ROWS) ?
1456
1456
                        info.touched : info.updated);
1457
1457
 
1458
 
  id= (thd->first_successful_insert_id_in_cur_stmt > 0) ?
1459
 
    thd->first_successful_insert_id_in_cur_stmt :
1460
 
    (thd->arg_of_last_insert_id_function ?
1461
 
     thd->first_successful_insert_id_in_prev_stmt :
 
1458
  id= (session->first_successful_insert_id_in_cur_stmt > 0) ?
 
1459
    session->first_successful_insert_id_in_cur_stmt :
 
1460
    (session->arg_of_last_insert_id_function ?
 
1461
     session->first_successful_insert_id_in_prev_stmt :
1462
1462
     (info.copied ? autoinc_value_of_last_inserted_row : 0));
1463
 
  ::my_ok(thd, (ulong) thd->row_count_func, id, buff);
 
1463
  ::my_ok(session, (ulong) session->row_count_func, id, buff);
1464
1464
  return(0);
1465
1465
}
1466
1466
 
1495
1495
    */
1496
1496
    changed= (info.copied || info.deleted || info.updated);
1497
1497
    transactional_table= table->file->has_transactions();
1498
 
    if (thd->transaction.stmt.modified_non_trans_table)
 
1498
    if (session->transaction.stmt.modified_non_trans_table)
1499
1499
    {
1500
1500
        if (mysql_bin_log.is_open())
1501
 
          thd->binlog_query(Session::ROW_QUERY_TYPE, thd->query, thd->query_length,
 
1501
          session->binlog_query(Session::ROW_QUERY_TYPE, session->query, session->query_length,
1502
1502
                            transactional_table, false);
1503
 
        if (!thd->current_stmt_binlog_row_based && !can_rollback_data())
1504
 
          thd->transaction.all.modified_non_trans_table= true;
 
1503
        if (!session->current_stmt_binlog_row_based && !can_rollback_data())
 
1504
          session->transaction.all.modified_non_trans_table= true;
1505
1505
    }
1506
1506
    assert(transactional_table || !changed ||
1507
 
                thd->transaction.stmt.modified_non_trans_table);
 
1507
                session->transaction.stmt.modified_non_trans_table);
1508
1508
    table->file->ha_release_auto_increment();
1509
1509
  }
1510
1510
 
1522
1522
 
1523
1523
  SYNOPSIS
1524
1524
    create_table_from_items()
1525
 
      thd          in     Thread object
 
1525
      session          in     Thread object
1526
1526
      create_info  in     Create information (like MAX_ROWS, ENGINE or
1527
1527
                          temporary table flag)
1528
1528
      create_table in     Pointer to TableList object providing database
1558
1558
    0         Error
1559
1559
*/
1560
1560
 
1561
 
static Table *create_table_from_items(Session *thd, HA_CREATE_INFO *create_info,
 
1561
static Table *create_table_from_items(Session *session, HA_CREATE_INFO *create_info,
1562
1562
                                      TableList *create_table,
1563
1563
                                      Alter_info *alter_info,
1564
1564
                                      List<Item> *items,
1582
1582
    if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)
1583
1583
    {
1584
1584
      create_info->table_existed= 1;            // Mark that table existed
1585
 
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
 
1585
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1586
1586
                          ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
1587
1587
                          create_table->table_name);
1588
1588
      return(create_table->table);
1595
1595
  tmp_table.alias= 0;
1596
1596
  tmp_table.timestamp_field= 0;
1597
1597
  tmp_table.s= &share;
1598
 
  init_tmp_table_share(thd, &share, "", 0, "", "");
 
1598
  init_tmp_table_share(session, &share, "", 0, "", "");
1599
1599
 
1600
1600
  tmp_table.s->db_create_options=0;
1601
1601
  tmp_table.s->blob_ptr_size= portable_sizeof_char_ptr;
1615
1615
      else
1616
1616
        field= item->tmp_table_field_from_field_type(&tmp_table, 0);
1617
1617
    else
1618
 
      field= create_tmp_field(thd, &tmp_table, item, item->type(),
 
1618
      field= create_tmp_field(session, &tmp_table, item, item->type(),
1619
1619
                              (Item ***) 0, &tmp_field, &def_field, 0, 0, 0, 0,
1620
1620
                              0);
1621
1621
    if (!field ||
1645
1645
    open_table().
1646
1646
  */
1647
1647
  {
1648
 
    tmp_disable_binlog(thd);
1649
 
    if (!mysql_create_table_no_lock(thd, create_table->db,
 
1648
    tmp_disable_binlog(session);
 
1649
    if (!mysql_create_table_no_lock(session, create_table->db,
1650
1650
                                    create_table->table_name,
1651
1651
                                    create_info, alter_info, 0,
1652
1652
                                    select_field_count, true))
1666
1666
      if (!(create_info->options & HA_LEX_CREATE_TMP_TABLE))
1667
1667
      {
1668
1668
        pthread_mutex_lock(&LOCK_open);
1669
 
        if (reopen_name_locked_table(thd, create_table, false))
 
1669
        if (reopen_name_locked_table(session, create_table, false))
1670
1670
        {
1671
1671
          quick_rm_table(create_info->db_type, create_table->db,
1672
1672
                         table_case_name(create_info, create_table->table_name),
1678
1678
      }
1679
1679
      else
1680
1680
      {
1681
 
        if (!(table= open_table(thd, create_table, (bool*) 0,
 
1681
        if (!(table= open_table(session, create_table, (bool*) 0,
1682
1682
                                DRIZZLE_OPEN_TEMPORARY_ONLY)) &&
1683
1683
            !create_info->table_existed)
1684
1684
        {
1687
1687
            it preparable for open. But let us do close_temporary_table() here
1688
1688
            just in case.
1689
1689
          */
1690
 
          drop_temporary_table(thd, create_table);
 
1690
          drop_temporary_table(session, create_table);
1691
1691
        }
1692
1692
      }
1693
1693
    }
1694
 
    reenable_binlog(thd);
 
1694
    reenable_binlog(session);
1695
1695
    if (!table)                                   // open failed
1696
1696
      return(0);
1697
1697
  }
1698
1698
 
1699
1699
  table->reginfo.lock_type=TL_WRITE;
1700
1700
  hooks->prelock(&table, 1);                    // Call prelock hooks
1701
 
  if (! ((*lock)= mysql_lock_tables(thd, &table, 1,
 
1701
  if (! ((*lock)= mysql_lock_tables(session, &table, 1,
1702
1702
                                    DRIZZLE_LOCK_IGNORE_FLUSH, &not_used)) ||
1703
1703
        hooks->postlock(&table, 1))
1704
1704
  {
1705
1705
    if (*lock)
1706
1706
    {
1707
 
      mysql_unlock_tables(thd, *lock);
 
1707
      mysql_unlock_tables(session, *lock);
1708
1708
      *lock= 0;
1709
1709
    }
1710
1710
 
1711
1711
    if (!create_info->table_existed)
1712
 
      drop_open_table(thd, table, create_table->db, create_table->table_name);
 
1712
      drop_open_table(session, table, create_table->db, create_table->table_name);
1713
1713
    return(0);
1714
1714
  }
1715
1715
  return(table);
1753
1753
  private:
1754
1754
    virtual int do_postlock(Table **tables, uint32_t count)
1755
1755
    {
1756
 
      Session *thd= const_cast<Session*>(ptr->get_thd());
1757
 
      if (int error= decide_logging_format(thd, &all_tables))
 
1756
      Session *session= const_cast<Session*>(ptr->get_session());
 
1757
      if (int error= decide_logging_format(session, &all_tables))
1758
1758
        return error;
1759
1759
 
1760
1760
      Table const *const table = *tables;
1761
 
      if (thd->current_stmt_binlog_row_based  &&
 
1761
      if (session->current_stmt_binlog_row_based  &&
1762
1762
          !table->s->tmp_table &&
1763
1763
          !ptr->get_create_info()->table_existed)
1764
1764
      {
1781
1781
    row-based replication for the statement.  If we are creating a
1782
1782
    temporary table, we need to start a statement transaction.
1783
1783
  */
1784
 
  if ((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0 &&
1785
 
      thd->current_stmt_binlog_row_based)
 
1784
  if ((session->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0 &&
 
1785
      session->current_stmt_binlog_row_based)
1786
1786
  {
1787
 
    thd->binlog_start_trans_and_stmt();
 
1787
    session->binlog_start_trans_and_stmt();
1788
1788
  }
1789
1789
 
1790
 
  if (!(table= create_table_from_items(thd, create_info, create_table,
 
1790
  if (!(table= create_table_from_items(session, create_info, create_table,
1791
1791
                                       alter_info, &values,
1792
1792
                                       &extra_lock, hook_ptr)))
1793
1793
    return(-1);                         // abort() deletes table
1799
1799
    if (create_info->options & HA_LEX_CREATE_TMP_TABLE)
1800
1800
      m_plock= &m_lock;
1801
1801
    else
1802
 
      m_plock= &thd->extra_lock;
 
1802
      m_plock= &session->extra_lock;
1803
1803
 
1804
1804
    *m_plock= extra_lock;
1805
1805
  }
1822
1822
  table->next_number_field=table->found_next_number_field;
1823
1823
 
1824
1824
  restore_record(table,s->default_values);      // Get empty record
1825
 
  thd->cuted_fields=0;
 
1825
  session->cuted_fields=0;
1826
1826
  if (info.ignore || info.handle_duplicates != DUP_ERROR)
1827
1827
    table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
1828
1828
  if (info.handle_duplicates == DUP_REPLACE)
1830
1830
  if (info.handle_duplicates == DUP_UPDATE)
1831
1831
    table->file->extra(HA_EXTRA_INSERT_WITH_UPDATE);
1832
1832
  table->file->ha_start_bulk_insert((ha_rows) 0);
1833
 
  thd->abort_on_warning= !info.ignore;
1834
 
  if (check_that_all_fields_are_given_values(thd, table, table_list))
 
1833
  session->abort_on_warning= !info.ignore;
 
1834
  if (check_that_all_fields_are_given_values(session, table, table_list))
1835
1835
    return(1);
1836
1836
  table->mark_columns_needed_for_insert();
1837
1837
  table->file->extra(HA_EXTRA_WRITE_CACHE);
1858
1858
    schema that will do a close_thread_tables(), destroying the
1859
1859
    statement transaction cache.
1860
1860
  */
1861
 
  assert(thd->current_stmt_binlog_row_based);
 
1861
  assert(session->current_stmt_binlog_row_based);
1862
1862
  assert(tables && *tables && count > 0);
1863
1863
 
1864
1864
  char buf[2048];
1870
1870
  tmp_table_list.table = *tables;
1871
1871
  query.length(0);      // Have to zero it since constructor doesn't
1872
1872
 
1873
 
  result= store_create_info(thd, &tmp_table_list, &query, create_info);
 
1873
  result= store_create_info(session, &tmp_table_list, &query, create_info);
1874
1874
  assert(result == 0); /* store_create_info() always return 0 */
1875
1875
 
1876
 
  thd->binlog_query(Session::STMT_QUERY_TYPE,
 
1876
  session->binlog_query(Session::STMT_QUERY_TYPE,
1877
1877
                    query.ptr(), query.length(),
1878
1878
                    /* is_trans */ true,
1879
1879
                    /* suppress_use */ false);
1881
1881
 
1882
1882
void select_create::store_values(List<Item> &values)
1883
1883
{
1884
 
  fill_record(thd, field, values, 1);
 
1884
  fill_record(session, field, values, 1);
1885
1885
}
1886
1886
 
1887
1887
 
1900
1900
    written to the binary log.
1901
1901
 
1902
1902
  */
1903
 
  tmp_disable_binlog(thd);
 
1903
  tmp_disable_binlog(session);
1904
1904
  select_insert::send_error(errcode, err);
1905
 
  reenable_binlog(thd);
 
1905
  reenable_binlog(session);
1906
1906
 
1907
1907
  return;
1908
1908
}
1922
1922
    */
1923
1923
    if (!table->s->tmp_table)
1924
1924
    {
1925
 
      ha_autocommit_or_rollback(thd, 0);
1926
 
      end_active_trans(thd);
 
1925
      ha_autocommit_or_rollback(session, 0);
 
1926
      end_active_trans(session);
1927
1927
    }
1928
1928
 
1929
1929
    table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
1930
1930
    table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
1931
1931
    if (m_plock)
1932
1932
    {
1933
 
      mysql_unlock_tables(thd, *m_plock);
 
1933
      mysql_unlock_tables(session, *m_plock);
1934
1934
      *m_plock= NULL;
1935
1935
      m_plock= NULL;
1936
1936
    }
1958
1958
    of the table succeeded or not, since we need to reset the binary
1959
1959
    log state.
1960
1960
  */
1961
 
  tmp_disable_binlog(thd);
 
1961
  tmp_disable_binlog(session);
1962
1962
  select_insert::abort();
1963
 
  thd->transaction.stmt.modified_non_trans_table= false;
1964
 
  reenable_binlog(thd);
 
1963
  session->transaction.stmt.modified_non_trans_table= false;
 
1964
  reenable_binlog(session);
1965
1965
 
1966
1966
 
1967
1967
  if (m_plock)
1968
1968
  {
1969
 
    mysql_unlock_tables(thd, *m_plock);
 
1969
    mysql_unlock_tables(session, *m_plock);
1970
1970
    *m_plock= NULL;
1971
1971
    m_plock= NULL;
1972
1972
  }
1976
1976
    table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
1977
1977
    table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
1978
1978
    if (!create_info->table_existed)
1979
 
      drop_open_table(thd, table, create_table->db, create_table->table_name);
 
1979
      drop_open_table(session, table, create_table->db, create_table->table_name);
1980
1980
    table=0;                                    // Safety
1981
1981
  }
1982
1982
  return;