~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/cursor.cc

  • Committer: Olaf van der Spek
  • Date: 2011-03-24 00:16:14 UTC
  • mto: This revision was merged to the branch mainline in revision 2251.
  • Revision ID: olafvdspek@gmail.com-20110324001614-wvmgc6eg52oq2321
Remove const_reference and reference from Session

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
  Handler-calling-functions
24
24
*/
25
25
 
26
 
#include "config.h"
27
 
 
 
26
#include <config.h>
28
27
#include <fcntl.h>
29
 
 
30
 
#include "drizzled/my_hash.h"
31
 
#include "drizzled/error.h"
32
 
#include "drizzled/gettext.h"
33
 
#include "drizzled/probes.h"
34
 
#include "drizzled/sql_parse.h"
35
 
#include "drizzled/optimizer/cost_vector.h"
36
 
#include "drizzled/session.h"
37
 
#include "drizzled/sql_base.h"
38
 
#include "drizzled/transaction_services.h"
39
 
#include "drizzled/lock.h"
40
 
#include "drizzled/item/int.h"
41
 
#include "drizzled/item/empty_string.h"
42
 
#include "drizzled/field/timestamp.h"
43
 
#include "drizzled/message/table.pb.h"
44
 
#include "drizzled/plugin/client.h"
45
 
#include "drizzled/internal/my_sys.h"
46
 
#include "drizzled/plugin/event_observer.h"
 
28
#include <drizzled/error.h>
 
29
#include <drizzled/field/epoch.h>
 
30
#include <drizzled/gettext.h>
 
31
#include <drizzled/internal/my_sys.h>
 
32
#include <drizzled/item/empty_string.h>
 
33
#include <drizzled/item/int.h>
 
34
#include <drizzled/lock.h>
 
35
#include <drizzled/message/table.h>
 
36
#include <drizzled/optimizer/cost_vector.h>
 
37
#include <drizzled/plugin/client.h>
 
38
#include <drizzled/plugin/event_observer.h>
 
39
#include <drizzled/plugin/storage_engine.h>
 
40
#include <drizzled/probes.h>
 
41
#include <drizzled/session.h>
 
42
#include <drizzled/sql_base.h>
 
43
#include <drizzled/sql_parse.h>
 
44
#include <drizzled/transaction_services.h>
 
45
#include <drizzled/key.h>
 
46
#include <drizzled/sql_lex.h>
 
47
#include <drizzled/resource_context.h>
 
48
#include <drizzled/statistics_variables.h>
 
49
#include <drizzled/system_variables.h>
47
50
 
48
51
using namespace std;
49
52
 
50
 
namespace drizzled
51
 
{
 
53
namespace drizzled {
52
54
 
53
55
/****************************************************************************
54
56
** General Cursor functions
90
92
  if (!(new_handler->ref= (unsigned char*) mem_root->alloc_root(ALIGN_SIZE(ref_length)*2)))
91
93
    return NULL;
92
94
 
93
 
  TableIdentifier identifier(getTable()->getShare()->getSchemaName(),
 
95
  identifier::Table identifier(getTable()->getShare()->getSchemaName(),
94
96
                             getTable()->getShare()->getTableName(),
95
97
                             getTable()->getShare()->getType());
96
98
 
210
212
uint64_t Cursor::tableSize() { return stats.index_file_length + stats.data_file_length; }
211
213
uint64_t Cursor::rowSize() { return getTable()->getRecordLength() + getTable()->sizeFields(); }
212
214
 
213
 
int Cursor::doOpen(const TableIdentifier &identifier, int mode, uint32_t test_if_locked)
 
215
int Cursor::doOpen(const identifier::Table &identifier, int mode, uint32_t test_if_locked)
214
216
{
215
217
  return open(identifier.getPath().c_str(), mode, test_if_locked);
216
218
}
221
223
  Try O_RDONLY if cannot open as O_RDWR
222
224
  Don't wait for locks if not HA_OPEN_WAIT_IF_LOCKED is set
223
225
*/
224
 
int Cursor::ha_open(const TableIdentifier &identifier,
 
226
int Cursor::ha_open(const identifier::Table &identifier,
225
227
                    int mode,
226
228
                    int test_if_locked)
227
229
{
266
268
*/
267
269
int Cursor::read_first_row(unsigned char * buf, uint32_t primary_key)
268
270
{
269
 
  register int error;
 
271
  int error;
270
272
 
271
273
  ha_statistic_increment(&system_status_var::ha_read_first_count);
272
274
 
273
275
  /*
274
276
    If there is very few deleted rows in the table, find the first row by
275
277
    scanning the table.
276
 
    TODO remove the test for HA_READ_ORDER
 
278
    @todo remove the test for HA_READ_ORDER
277
279
  */
278
280
  if (stats.deleted < 10 || primary_key >= MAX_KEY ||
279
281
      !(getTable()->index_flags(primary_key) & HA_READ_ORDER))
280
282
  {
281
 
    (void) startTableScan(1);
282
 
    while ((error= rnd_next(buf)) == HA_ERR_RECORD_DELETED) ;
283
 
    (void) endTableScan();
 
283
    error= startTableScan(1);
 
284
    if (error == 0)
 
285
    {
 
286
      while ((error= rnd_next(buf)) == HA_ERR_RECORD_DELETED) ;
 
287
      (void) endTableScan();
 
288
    }
284
289
  }
285
290
  else
286
291
  {
287
292
    /* Find the first row through the primary key */
288
 
    (void) startIndexScan(primary_key, 0);
289
 
    error=index_first(buf);
290
 
    (void) endIndexScan();
 
293
    error= startIndexScan(primary_key, 0);
 
294
    if (error == 0)
 
295
    {
 
296
      error=index_first(buf);
 
297
      (void) endIndexScan();
 
298
    }
291
299
  }
292
300
  return error;
293
301
}
471
479
 
472
480
  if ((nr= next_insert_id) >= auto_inc_interval_for_cur_row.maximum())
473
481
  {
474
 
    /* next_insert_id is beyond what is reserved, so we reserve more. */
475
 
    const Discrete_interval *forced=
476
 
      session->auto_inc_intervals_forced.get_next();
477
 
    if (forced != NULL)
478
 
    {
479
 
      nr= forced->minimum();
480
 
      nb_reserved_values= forced->values();
481
 
    }
482
 
    else
483
482
    {
484
483
      /*
485
484
        Cursor::estimation_rows_to_insert was set by
486
485
        Cursor::ha_start_bulk_insert(); if 0 it means "unknown".
487
486
      */
488
 
      uint32_t nb_already_reserved_intervals=
489
 
        session->auto_inc_intervals_in_cur_stmt_for_binlog.nb_elements();
 
487
      uint32_t nb_already_reserved_intervals= 0;
490
488
      uint64_t nb_desired_values;
491
489
      /*
492
490
        If an estimation was given to the engine:
561
559
      nr= getTable()->next_number_field->val_int();
562
560
  }
563
561
  if (append)
564
 
  {
565
 
    auto_inc_interval_for_cur_row.replace(nr, nb_reserved_values,
566
 
                                          variables->auto_increment_increment);
567
 
  }
 
562
    auto_inc_interval_for_cur_row.replace(nr, nb_reserved_values, variables->auto_increment_increment);
568
563
 
569
564
  /*
570
565
    Record this autogenerated value. If the caller then
605
600
  release_auto_increment();
606
601
  insert_id_for_cur_row= 0;
607
602
  auto_inc_interval_for_cur_row.replace(0, 0, 0);
608
 
  if (next_insert_id > 0)
609
 
  {
610
 
    next_insert_id= 0;
611
 
    /*
612
 
      this statement used forced auto_increment values if there were some,
613
 
      wipe them away for other statements.
614
 
    */
615
 
    getTable()->in_use->auto_inc_intervals_forced.empty();
616
 
  }
 
603
  next_insert_id= 0;
617
604
}
618
605
 
619
606
void Cursor::drop_table(const char *)
651
638
void
652
639
Cursor::setTransactionReadWrite()
653
640
{
654
 
  ResourceContext *resource_context;
655
 
 
656
641
  /*
657
642
   * If the cursor has not context for execution then there should be no
658
643
   * possible resource to gain (and if there is... then there is a bug such
661
646
  if (not getTable()->in_use)
662
647
    return;
663
648
 
664
 
  resource_context= getTable()->in_use->getResourceContext(getEngine());
665
649
  /*
666
650
    When a storage engine method is called, the transaction must
667
651
    have been started, unless it's a DDL call, for which the
670
654
    Unfortunately here we can't know know for sure if the engine
671
655
    has registered the transaction or not, so we must check.
672
656
  */
673
 
  if (resource_context->isStarted())
674
 
  {
675
 
    resource_context->markModifiedData();
676
 
  }
 
657
  ResourceContext& resource_context= getTable()->in_use->getResourceContext(*getEngine());
 
658
  if (resource_context.isStarted())
 
659
    resource_context.markModifiedData();
677
660
}
678
661
 
679
662
 
704
687
     */
705
688
    Session *const session= getTable()->in_use;
706
689
    TransactionServices &transaction_services= TransactionServices::singleton();
707
 
    transaction_services.truncateTable(session, getTable());
 
690
    transaction_services.truncateTable(*session, *getTable());
708
691
  }
709
692
 
710
693
  return result;
1293
1276
 
1294
1277
  bool result= false;
1295
1278
 
1296
 
  switch (session->lex->sql_command)
 
1279
  switch (session->lex().sql_command)
1297
1280
  {
1298
1281
  case SQLCOM_CREATE_TABLE:
1299
1282
    /*
1305
1288
     * CREATE TABLE will commit the transaction containing
1306
1289
     * it).
1307
1290
     */
1308
 
    result= transaction_services.insertRecord(session, table);
 
1291
    result= transaction_services.insertRecord(*session, *table);
1309
1292
    break;
1310
1293
  case SQLCOM_REPLACE:
1311
1294
  case SQLCOM_REPLACE_SELECT:
1334
1317
       * as the row to delete (this is the conflicting row), so
1335
1318
       * we need to notify TransactionService to use that row.
1336
1319
       */
1337
 
      transaction_services.deleteRecord(session, table, true);
 
1320
      transaction_services.deleteRecord(*session, *table, true);
1338
1321
      /* 
1339
1322
       * We set the "current" statement message to NULL.  This triggers
1340
1323
       * the replication services component to generate a new statement
1341
1324
       * message for the inserted record which will come next.
1342
1325
       */
1343
 
      transaction_services.finalizeStatementMessage(*session->getStatementMessage(), session);
 
1326
      transaction_services.finalizeStatementMessage(*session->getStatementMessage(), *session);
1344
1327
    }
1345
1328
    else
1346
1329
    {
1347
1330
      if (before_record == NULL)
1348
 
        result= transaction_services.insertRecord(session, table);
 
1331
        result= transaction_services.insertRecord(*session, *table);
1349
1332
      else
1350
 
        transaction_services.updateRecord(session, table, before_record, after_record);
 
1333
        transaction_services.updateRecord(*session, *table, before_record, after_record);
1351
1334
    }
1352
1335
    break;
1353
1336
  case SQLCOM_INSERT:
1360
1343
     * an update.
1361
1344
     */
1362
1345
    if (before_record == NULL)
1363
 
      result= transaction_services.insertRecord(session, table);
 
1346
      result= transaction_services.insertRecord(*session, *table);
1364
1347
    else
1365
 
      transaction_services.updateRecord(session, table, before_record, after_record);
 
1348
      transaction_services.updateRecord(*session, *table, before_record, after_record);
1366
1349
    break;
1367
1350
 
1368
1351
  case SQLCOM_UPDATE:
1369
 
    transaction_services.updateRecord(session, table, before_record, after_record);
 
1352
    transaction_services.updateRecord(*session, *table, before_record, after_record);
1370
1353
    break;
1371
1354
 
1372
1355
  case SQLCOM_DELETE:
1373
 
    transaction_services.deleteRecord(session, table);
 
1356
    transaction_services.deleteRecord(*session, *table);
1374
1357
    break;
1375
1358
  default:
1376
1359
    break;