~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: David Shrewsbury
  • Date: 2010-11-19 15:23:07 UTC
  • mto: (1942.1.3 b)
  • mto: This revision was merged to the branch mainline in revision 1943.
  • Revision ID: shrewsbury.dave@gmail.com-20101119152307-srnssq2n5num5tit
Add --replicate-query option.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include <drizzled/statement.h>
40
40
#include <drizzled/statement/alter_table.h>
41
41
#include "drizzled/probes.h"
42
 
#include "drizzled/session/cache.h"
 
42
#include "drizzled/session_list.h"
43
43
#include "drizzled/global_charset_info.h"
44
44
 
45
45
#include "drizzled/plugin/logging.h"
54
54
 
55
55
#include <bitset>
56
56
#include <algorithm>
57
 
#include <boost/date_time.hpp>
 
57
 
58
58
#include "drizzled/internal/my_sys.h"
59
59
 
60
60
using namespace std;
222
222
      break;                                    // fatal error is set
223
223
    DRIZZLE_QUERY_START(session->getQueryString()->c_str(),
224
224
                        session->thread_id,
225
 
                        const_cast<const char *>(session->schema()->c_str()));
 
225
                        const_cast<const char *>(session->db.empty() ? "" : session->db.c_str()));
226
226
 
 
227
    plugin::QueryRewriter::rewriteQuery(session->getSchema(), session->getQueryString());
227
228
    mysql_parse(session, session->getQueryString()->c_str(), session->getQueryString()->length());
228
229
 
229
230
    break;
716
717
 
717
718
void mysql_parse(Session *session, const char *inBuf, uint32_t length)
718
719
{
719
 
  boost::posix_time::ptime start_time=boost::posix_time::microsec_clock::local_time();
 
720
  uint64_t start_time= my_getsystime();
720
721
  session->lex->start(session);
721
 
 
722
722
  session->reset_for_next_command();
723
723
  /* Check if the Query is Cached if and return true if yes
724
724
   * TODO the plugin has to make sure that the query is cacheble
743
743
      {
744
744
        DRIZZLE_QUERY_EXEC_START(session->getQueryString()->c_str(),
745
745
                                 session->thread_id,
746
 
                                 const_cast<const char *>(session->schema()->c_str()));
 
746
                                 const_cast<const char *>(session->db.empty() ? "" : session->db.c_str()));
747
747
        // Implement Views here --Brian
748
748
        /* Actually execute the query */
749
749
        try 
754
754
        {
755
755
          // Just try to catch any random failures that could have come
756
756
          // during execution.
757
 
          unireg_abort(1);
758
757
        }
759
758
        DRIZZLE_QUERY_EXEC_DONE(0);
760
759
      }
768
767
  session->set_proc_info("freeing items");
769
768
  session->end_statement();
770
769
  session->cleanup_after_query();
771
 
  boost::posix_time::ptime end_time=boost::posix_time::microsec_clock::local_time();
772
 
  session->status_var.execution_time_nsec+=(end_time-start_time).total_microseconds();
 
770
  session->status_var.execution_time_nsec+= my_getsystime() - start_time;
773
771
}
774
772
 
775
773
 
959
957
 
960
958
  ptr->alias= alias_str;
961
959
  ptr->setIsAlias(alias ? true : false);
 
960
  if (table->table.length)
 
961
    table->table.length= my_casedn_str(files_charset_info, table->table.str);
962
962
  ptr->setTableName(table->table.str);
963
963
  ptr->table_name_length=table->table.length;
964
964
  ptr->lock_type=   lock_type;
1415
1415
 
1416
1416
 
1417
1417
/**
 
1418
  kill on thread.
 
1419
 
 
1420
  @param session                        Thread class
 
1421
  @param id                     Thread id
 
1422
  @param only_kill_query        Should it kill the query or the connection
 
1423
 
 
1424
  @note
 
1425
    This is written such that we have a short lock on LOCK_thread_count
 
1426
*/
 
1427
 
 
1428
static unsigned int kill_one_thread(session_id_t id, bool only_kill_query)
 
1429
{
 
1430
  uint32_t error= ER_NO_SUCH_THREAD;
 
1431
  
 
1432
  Session::shared_ptr session= session::Cache::singleton().find(id);
 
1433
 
 
1434
  if (not session)
 
1435
    return error;
 
1436
 
 
1437
  if (session->isViewable())
 
1438
  {
 
1439
    session->awake(only_kill_query ? Session::KILL_QUERY : Session::KILL_CONNECTION);
 
1440
    error= 0;
 
1441
  }
 
1442
 
 
1443
  return error;
 
1444
}
 
1445
 
 
1446
 
 
1447
/*
 
1448
  kills a thread and sends response
 
1449
 
 
1450
  SYNOPSIS
 
1451
    sql_kill()
 
1452
    session                     Thread class
 
1453
    id                  Thread id
 
1454
    only_kill_query     Should it kill the query or the connection
 
1455
*/
 
1456
 
 
1457
void sql_kill(Session *session, int64_t id, bool only_kill_query)
 
1458
{
 
1459
  uint32_t error;
 
1460
 
 
1461
  if (not (error= kill_one_thread(id, only_kill_query)))
 
1462
    session->my_ok();
 
1463
  else
 
1464
    my_error(error, MYF(0), id);
 
1465
}
 
1466
 
 
1467
 
 
1468
/**
1418
1469
  Check if the select is a simple select (not an union).
1419
1470
 
1420
1471
  @retval
1542
1593
 
1543
1594
 
1544
1595
/**
 
1596
  CREATE TABLE query pre-check.
 
1597
 
 
1598
  @param session                        Thread handler
 
1599
  @param tables         Global table list
 
1600
  @param create_table           Table which will be created
 
1601
 
 
1602
  @retval
 
1603
    false   OK
 
1604
  @retval
 
1605
    true   Error
 
1606
*/
 
1607
 
 
1608
bool create_table_precheck(TableIdentifier &identifier)
 
1609
{
 
1610
  if (not plugin::StorageEngine::canCreateTable(identifier))
 
1611
  {
 
1612
    my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", identifier.getSchemaName().c_str());
 
1613
    return true;
 
1614
  }
 
1615
 
 
1616
  if (not plugin::StorageEngine::doesSchemaExist(identifier))
 
1617
  {
 
1618
    my_error(ER_BAD_DB_ERROR, MYF(0), identifier.getSchemaName().c_str());
 
1619
    return true;
 
1620
  }
 
1621
 
 
1622
  return false;
 
1623
}
 
1624
 
 
1625
 
 
1626
/**
1545
1627
  negate given expression.
1546
1628
 
1547
1629
  @param session  thread handler