~drizzle-developers/ubuntu/karmic/drizzle/ppa

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: Monty Taylor
  • Date: 2010-11-24 18:44:57 UTC
  • mfrom: (1308.1.31 trunk)
  • Revision ID: mordred@inaugust.com-20101124184457-qd6jvoe2wgnvl3yq
Tags: 2010.11.04-0ubuntu1~karmic1
* New upstream release.
* Turn off -Werror for packaging builds. (Closes: #602662)

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
 
55
55
#include <bitset>
56
56
#include <algorithm>
57
 
 
 
57
#include <boost/date_time.hpp>
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,
174
 
                        command);
 
173
  DRIZZLE_COMMAND_START(session->thread_id, command);
175
174
 
176
175
  session->command= command;
177
176
  session->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
219
218
  }
220
219
  case COM_QUERY:
221
220
  {
222
 
    if (! session->readAndStoreQuery(packet, packet_length))
 
221
    if (not session->readAndStoreQuery(packet, packet_length))
223
222
      break;                                    // fatal error is set
224
 
    DRIZZLE_QUERY_START(session->query.c_str(),
 
223
    DRIZZLE_QUERY_START(session->getQueryString()->c_str(),
225
224
                        session->thread_id,
226
225
                        const_cast<const char *>(session->db.empty() ? "" : session->db.c_str()));
227
226
 
228
 
    plugin::QueryRewriter::rewriteQuery(session->db, session->query);
229
 
    mysql_parse(session, session->query.c_str(), session->query.length());
 
227
    plugin::QueryRewriter::rewriteQuery(session->getSchema(), session->getQueryString());
 
228
    mysql_parse(session, session->getQueryString()->c_str(), session->getQueryString()->length());
230
229
 
231
230
    break;
232
231
  }
320
319
  /* Store temp state for processlist */
321
320
  session->set_proc_info("cleaning up");
322
321
  session->command= COM_SLEEP;
323
 
  memset(session->process_list_info, 0, PROCESS_LIST_WIDTH);
324
 
  session->query.clear();
 
322
  session->resetQueryString();
325
323
 
326
324
  session->set_proc_info(NULL);
327
325
  session->mem_root->free_root(MYF(memory::KEEP_PREALLOC));
432
430
    true        Error
433
431
*/
434
432
 
435
 
static int
436
 
mysql_execute_command(Session *session)
 
433
static int mysql_execute_command(Session *session)
437
434
{
438
435
  bool res= false;
439
436
  LEX  *lex= session->lex;
441
438
  Select_Lex *select_lex= &lex->select_lex;
442
439
  /* list of all tables in query */
443
440
  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';
450
441
 
451
442
  /*
452
443
    In many cases first table of main Select_Lex have special meaning =>
726
717
 
727
718
void mysql_parse(Session *session, const char *inBuf, uint32_t length)
728
719
{
729
 
  uint64_t start_time= my_getsystime();
 
720
  boost::posix_time::ptime start_time=boost::posix_time::microsec_clock::local_time();
730
721
  session->lex->start(session);
 
722
 
731
723
  session->reset_for_next_command();
732
724
  /* Check if the Query is Cached if and return true if yes
733
725
   * TODO the plugin has to make sure that the query is cacheble
748
740
  if (!err)
749
741
  {
750
742
    {
751
 
      if (! session->is_error())
 
743
      if (not session->is_error())
752
744
      {
753
 
        DRIZZLE_QUERY_EXEC_START(session->query.c_str(),
 
745
        DRIZZLE_QUERY_EXEC_START(session->getQueryString()->c_str(),
754
746
                                 session->thread_id,
755
747
                                 const_cast<const char *>(session->db.empty() ? "" : session->db.c_str()));
756
748
        // Implement Views here --Brian
776
768
  session->set_proc_info("freeing items");
777
769
  session->end_statement();
778
770
  session->cleanup_after_query();
779
 
  session->status_var.execution_time_nsec+= my_getsystime() - start_time;
 
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();
780
773
}
781
774
 
782
775
 
966
959
 
967
960
  ptr->alias= alias_str;
968
961
  ptr->setIsAlias(alias ? true : false);
969
 
  if (table->table.length)
970
 
    table->table.length= my_casedn_str(files_charset_info, table->table.str);
971
962
  ptr->setTableName(table->table.str);
972
963
  ptr->table_name_length=table->table.length;
973
964
  ptr->lock_type=   lock_type;
1424
1415
 
1425
1416
 
1426
1417
/**
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
 
/**
1492
1418
  Check if the select is a simple select (not an union).
1493
1419
 
1494
1420
  @retval
1771
1697
{
1772
1698
  assert(session->m_lip == NULL);
1773
1699
 
1774
 
  DRIZZLE_QUERY_PARSE_START(session->query.c_str());
 
1700
  DRIZZLE_QUERY_PARSE_START(session->getQueryString()->c_str());
1775
1701
 
1776
1702
  /* Set Lex_input_stream. */
1777
1703