~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: Stewart Smith
  • Date: 2010-11-03 03:29:48 UTC
  • mto: (1902.1.1 build) (1910.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1903.
  • Revision ID: stewart@flamingspork.com-20101103032948-ocaksrku0oqxw8aa
fix more docs warnings: underline/overline too short

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;
170
170
  bool error= 0;
171
171
  Query_id &query_id= Query_id::get_query_id();
172
172
 
173
 
  DRIZZLE_COMMAND_START(session->thread_id, command);
 
173
  DRIZZLE_COMMAND_START(session->thread_id,
 
174
                        command);
174
175
 
175
176
  session->command= command;
176
177
  session->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
218
219
  }
219
220
  case COM_QUERY:
220
221
  {
221
 
    if (not session->readAndStoreQuery(packet, packet_length))
 
222
    if (! session->readAndStoreQuery(packet, packet_length))
222
223
      break;                                    // fatal error is set
223
 
    DRIZZLE_QUERY_START(session->getQueryString()->c_str(),
 
224
    DRIZZLE_QUERY_START(session->query.c_str(),
224
225
                        session->thread_id,
225
 
                        const_cast<const char *>(session->schema()->c_str()));
 
226
                        const_cast<const char *>(session->db.empty() ? "" : session->db.c_str()));
226
227
 
227
 
    mysql_parse(session, session->getQueryString()->c_str(), session->getQueryString()->length());
 
228
    plugin::QueryRewriter::rewriteQuery(session->db, session->query);
 
229
    mysql_parse(session, session->query.c_str(), session->query.length());
228
230
 
229
231
    break;
230
232
  }
269
271
    if (! session->main_da.is_set())
270
272
      session->send_kill_message();
271
273
  }
272
 
  if (session->getKilled() == Session::KILL_QUERY || session->getKilled() == Session::KILL_BAD_DATA)
 
274
  if (session->killed == Session::KILL_QUERY || session->killed == Session::KILL_BAD_DATA)
273
275
  {
274
 
    session->setKilled(Session::NOT_KILLED);
 
276
    session->killed= Session::NOT_KILLED;
275
277
    session->setAbort(false);
276
278
  }
277
279
 
318
320
  /* Store temp state for processlist */
319
321
  session->set_proc_info("cleaning up");
320
322
  session->command= COM_SLEEP;
321
 
  session->resetQueryString();
 
323
  memset(session->process_list_info, 0, PROCESS_LIST_WIDTH);
 
324
  session->query.clear();
322
325
 
323
326
  session->set_proc_info(NULL);
324
327
  session->mem_root->free_root(MYF(memory::KEEP_PREALLOC));
429
432
    true        Error
430
433
*/
431
434
 
432
 
static int mysql_execute_command(Session *session)
 
435
static int
 
436
mysql_execute_command(Session *session)
433
437
{
434
438
  bool res= false;
435
439
  LEX  *lex= session->lex;
437
441
  Select_Lex *select_lex= &lex->select_lex;
438
442
  /* list of all tables in query */
439
443
  TableList *all_tables;
 
444
  /* A peek into the query string */
 
445
  size_t proc_info_len= session->query.length() > PROCESS_LIST_WIDTH ?
 
446
                        PROCESS_LIST_WIDTH : session->query.length();
 
447
 
 
448
  memcpy(session->process_list_info, session->query.c_str(), proc_info_len);
 
449
  session->process_list_info[proc_info_len]= '\0';
440
450
 
441
451
  /*
442
452
    In many cases first table of main Select_Lex have special meaning =>
716
726
 
717
727
void mysql_parse(Session *session, const char *inBuf, uint32_t length)
718
728
{
719
 
  boost::posix_time::ptime start_time=boost::posix_time::microsec_clock::local_time();
720
 
  session->lex->start(session);
721
 
 
 
729
  uint64_t start_time= my_getsystime();
 
730
  lex_start(session);
722
731
  session->reset_for_next_command();
723
732
  /* Check if the Query is Cached if and return true if yes
724
733
   * TODO the plugin has to make sure that the query is cacheble
739
748
  if (!err)
740
749
  {
741
750
    {
742
 
      if (not session->is_error())
 
751
      if (! session->is_error())
743
752
      {
744
 
        DRIZZLE_QUERY_EXEC_START(session->getQueryString()->c_str(),
 
753
        DRIZZLE_QUERY_EXEC_START(session->query.c_str(),
745
754
                                 session->thread_id,
746
 
                                 const_cast<const char *>(session->schema()->c_str()));
 
755
                                 const_cast<const char *>(session->db.empty() ? "" : session->db.c_str()));
747
756
        // Implement Views here --Brian
748
757
        /* Actually execute the query */
749
758
        try 
754
763
        {
755
764
          // Just try to catch any random failures that could have come
756
765
          // during execution.
757
 
          unireg_abort(1);
758
766
        }
759
767
        DRIZZLE_QUERY_EXEC_DONE(0);
760
768
      }
768
776
  session->set_proc_info("freeing items");
769
777
  session->end_statement();
770
778
  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();
 
779
  session->status_var.execution_time_nsec+= my_getsystime() - start_time;
773
780
}
774
781
 
775
782
 
959
966
 
960
967
  ptr->alias= alias_str;
961
968
  ptr->setIsAlias(alias ? true : false);
 
969
  if (table->table.length)
 
970
    table->table.length= my_casedn_str(files_charset_info, table->table.str);
962
971
  ptr->setTableName(table->table.str);
963
972
  ptr->table_name_length=table->table.length;
964
973
  ptr->lock_type=   lock_type;
1415
1424
 
1416
1425
 
1417
1426
/**
 
1427
  kill on thread.
 
1428
 
 
1429
  @param session                        Thread class
 
1430
  @param id                     Thread id
 
1431
  @param only_kill_query        Should it kill the query or the connection
 
1432
 
 
1433
  @note
 
1434
    This is written such that we have a short lock on LOCK_thread_count
 
1435
*/
 
1436
 
 
1437
static unsigned int
 
1438
kill_one_thread(Session *, session_id_t id, bool only_kill_query)
 
1439
{
 
1440
  Session *tmp= NULL;
 
1441
  uint32_t error= ER_NO_SUCH_THREAD;
 
1442
  
 
1443
  {
 
1444
    boost::mutex::scoped_lock scoped(LOCK_thread_count);
 
1445
    for (SessionList::iterator it= getSessionList().begin(); it != getSessionList().end(); ++it )
 
1446
    {
 
1447
      if ((*it)->thread_id == id)
 
1448
      {
 
1449
        tmp= *it;
 
1450
        tmp->lockForDelete();
 
1451
        break;
 
1452
      }
 
1453
    }
 
1454
  }
 
1455
 
 
1456
  if (tmp)
 
1457
  {
 
1458
 
 
1459
    if (tmp->isViewable())
 
1460
    {
 
1461
      tmp->awake(only_kill_query ? Session::KILL_QUERY : Session::KILL_CONNECTION);
 
1462
      error= 0;
 
1463
    }
 
1464
 
 
1465
    tmp->unlockForDelete();
 
1466
  }
 
1467
  return(error);
 
1468
}
 
1469
 
 
1470
 
 
1471
/*
 
1472
  kills a thread and sends response
 
1473
 
 
1474
  SYNOPSIS
 
1475
    sql_kill()
 
1476
    session                     Thread class
 
1477
    id                  Thread id
 
1478
    only_kill_query     Should it kill the query or the connection
 
1479
*/
 
1480
 
 
1481
void sql_kill(Session *session, int64_t id, bool only_kill_query)
 
1482
{
 
1483
  uint32_t error;
 
1484
  if (!(error= kill_one_thread(session, id, only_kill_query)))
 
1485
    session->my_ok();
 
1486
  else
 
1487
    my_error(error, MYF(0), id);
 
1488
}
 
1489
 
 
1490
 
 
1491
/**
1418
1492
  Check if the select is a simple select (not an union).
1419
1493
 
1420
1494
  @retval
1542
1616
 
1543
1617
 
1544
1618
/**
 
1619
  CREATE TABLE query pre-check.
 
1620
 
 
1621
  @param session                        Thread handler
 
1622
  @param tables         Global table list
 
1623
  @param create_table           Table which will be created
 
1624
 
 
1625
  @retval
 
1626
    false   OK
 
1627
  @retval
 
1628
    true   Error
 
1629
*/
 
1630
 
 
1631
bool create_table_precheck(TableIdentifier &identifier)
 
1632
{
 
1633
  if (not plugin::StorageEngine::canCreateTable(identifier))
 
1634
  {
 
1635
    my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", identifier.getSchemaName().c_str());
 
1636
    return true;
 
1637
  }
 
1638
 
 
1639
  if (not plugin::StorageEngine::doesSchemaExist(identifier))
 
1640
  {
 
1641
    my_error(ER_BAD_DB_ERROR, MYF(0), identifier.getSchemaName().c_str());
 
1642
    return true;
 
1643
  }
 
1644
 
 
1645
  return false;
 
1646
}
 
1647
 
 
1648
 
 
1649
/**
1545
1650
  negate given expression.
1546
1651
 
1547
1652
  @param session  thread handler
1666
1771
{
1667
1772
  assert(session->m_lip == NULL);
1668
1773
 
1669
 
  DRIZZLE_QUERY_PARSE_START(session->getQueryString()->c_str());
 
1774
  DRIZZLE_QUERY_PARSE_START(session->query.c_str());
1670
1775
 
1671
1776
  /* Set Lex_input_stream. */
1672
1777