~maria-captains/maria/maria-5.3-qclexcheck

« back to all changes in this revision

Viewing changes to sql/sql_cache.cc

  • Committer: sanja at montyprogram
  • Date: 2012-02-07 13:01:11 UTC
  • Revision ID: sanja@montyprogram.com-20120207130111-3d2xmnjg8xyy5o4h
more cache statistic + additional check

Show diffs side-by-side

added added

removed removed

Lines of Context:
1093
1093
    // The following call will remove the lock on query_block
1094
1094
    query_cache.free_query(query_block);
1095
1095
    query_cache.refused++;
 
1096
    query_cache.refused_upnd++;
1096
1097
    // append_result_data no success => we need unlock
1097
1098
    query_cache.unlock();
1098
1099
    DBUG_VOID_RETURN;
1257
1258
  :query_cache_size(0),
1258
1259
   query_cache_limit(query_cache_limit_arg),
1259
1260
   queries_in_cache(0), hits(0), inserts(0), refused(0),
 
1261
   refused_upnd(0), refused_rsz(0), refused_hndlr(0), refused_applc(0),
 
1262
   refused_nosel(0), refused_insrt(0), refused_regtab(0), refused_alloc(0),
 
1263
   refused_othd(0), reused_utbl(0), refused_abrt(0),
 
1264
   reject_nosel(0), reject_nocache(0), reject_dbchanged(0),
 
1265
   reject_noquery(0), reject_nodata(0), reject_tmptab(0),
 
1266
   reject_noacc(0), reject_engine(0), reject_noapplc(0),
1260
1267
   total_blocks(0), lowmem_prunes(0),
1261
1268
   m_cache_status(OK),
1262
1269
   min_allocation_unit(ALIGN_SIZE(min_allocation_unit_arg)),
1311
1318
        query->writer()->query_cache_query= 0;
1312
1319
        query->writer(0);
1313
1320
        refused++;
 
1321
        refused_rsz++;
1314
1322
      }
1315
1323
      BLOCK_UNLOCK_WR(block);
1316
1324
      block= block->next;
1362
1370
 
1363
1371
    See also a note on double-check locking usage above.
1364
1372
  */
1365
 
  if (!thd->query_cache_is_applicable || query_cache_size == 0)
 
1373
  if (thd->locked_tables || !thd->lex->safe_to_cache_query ||
 
1374
      !thd->query_cache_is_applicable || query_cache_size == 0)
1366
1375
  {
 
1376
    if (!thd->query_cache_is_applicable || !thd->lex->safe_to_cache_query)
 
1377
      refused_applc++;
1367
1378
    DBUG_PRINT("qcache", ("Query cache not ready"));
1368
1379
    DBUG_VOID_RETURN;
1369
1380
  }
1370
1381
  if (thd->lex->sql_command != SQLCOM_SELECT)
1371
1382
  {
 
1383
    refused_nosel++;
1372
1384
    DBUG_PRINT("qcache", ("Ignoring not SELECT command"));
1373
1385
    DBUG_VOID_RETURN;
1374
1386
  }
1467
1479
    if (ask_handler_allowance(thd, tables_used))
1468
1480
    {
1469
1481
      refused++;
 
1482
      refused_hndlr++;
1470
1483
      unlock();
1471
1484
      DBUG_VOID_RETURN;
1472
1485
    }
1516
1529
        if (my_hash_insert(&queries, (uchar*) query_block))
1517
1530
        {
1518
1531
          refused++;
 
1532
          refused_insrt++;
1519
1533
          DBUG_PRINT("qcache", ("insertion in query hash"));
1520
1534
          header->unlock_n_destroy();
1521
1535
          free_memory_block(query_block);
1525
1539
        if (!register_all_tables(query_block, tables_used, local_tables))
1526
1540
        {
1527
1541
          refused++;
 
1542
          refused_regtab++;
1528
1543
          DBUG_PRINT("warning", ("tables list including failed"));
1529
1544
          hash_delete(&queries, (uchar *) query_block);
1530
1545
          header->unlock_n_destroy();
1548
1563
      {
1549
1564
        // We have not enough memory to store query => do nothing
1550
1565
        refused++;
 
1566
        refused_alloc++;
1551
1567
        unlock();
1552
1568
        DBUG_PRINT("warning", ("Can't allocate query"));
1553
1569
      }
1556
1572
    {
1557
1573
      // Another thread is processing the same query => do nothing
1558
1574
      refused++;
 
1575
      refused_othd++;
1559
1576
      unlock();
1560
1577
      DBUG_PRINT("qcache", ("Another thread process same query"));
1561
1578
    }
1562
1579
  }
1563
1580
  else
 
1581
  {
1564
1582
    statistic_increment(refused, &structure_guard_mutex);
 
1583
    reused_utbl++;
 
1584
  }
1565
1585
 
1566
1586
end:
1567
1587
  DBUG_VOID_RETURN;
1659
1679
  if (is_disabled() || thd->locked_tables ||
1660
1680
      thd->variables.query_cache_type == 0)
1661
1681
    goto err;
1662
 
  DBUG_ASSERT(query_cache_size != 0);           // otherwise cache would be disabled
 
1682
  DBUG_ASSERT(query_cache_size != 0);   // otherwise cache would be disabled
 
1683
 
 
1684
  if (!thd->lex->safe_to_cache_query)
 
1685
  {
 
1686
    reject_noapplc++;
 
1687
    DBUG_PRINT("qcache", ("query is not applicable"));
 
1688
    goto err;
 
1689
  }
1663
1690
 
1664
1691
  thd->query_cache_is_applicable= 1;
1665
1692
  sql= org_sql; sql_end= sql + query_length;
1742
1769
       my_toupper(system_charset_info, sql[2]) != 'L'))
1743
1770
  {
1744
1771
    DBUG_PRINT("qcache", ("The statement is not a SELECT; Not cached"));
 
1772
    reject_nosel++;
1745
1773
    goto err;
1746
1774
  }
1747
1775
 
1752
1780
      later when the query is parsed.
1753
1781
    */
1754
1782
    DBUG_PRINT("qcache", ("The statement has a SQL_NO_CACHE directive"));
 
1783
    reject_nocache++;
1755
1784
    goto err;
1756
1785
  }
1757
1786
  {
1770
1799
        We should probably reallocate the buffer in this case,
1771
1800
        but for now we just leave it uncached
1772
1801
      */
1773
 
 
 
1802
      reject_dbchanged++;
1774
1803
      DBUG_PRINT("qcache", 
1775
1804
                 ("Current database has changed since start of query"));
1776
1805
      goto err;
1885
1914
      query_block->query()->result() == 0 ||
1886
1915
      query_block->query()->result()->type != Query_cache_block::RESULT)
1887
1916
  {
 
1917
    reject_noquery++;
1888
1918
    DBUG_PRINT("qcache", ("No query in query hash or no results"));
1889
1919
    goto err_unlock;
1890
1920
  }
1901
1931
 
1902
1932
  if (result_block == 0 || result_block->type != Query_cache_block::RESULT)
1903
1933
  {
 
1934
    reject_nodata++;
1904
1935
    /* The query is probably yet processed */
1905
1936
    DBUG_PRINT("qcache", ("query found, but no data or data incomplete"));
1906
1937
    BLOCK_UNLOCK_RD(query_block);
1940
1971
          !memcmp(tmptable->s->table_cache_key.str, table->data(),
1941
1972
                  table->key_length()))
1942
1973
      {
 
1974
        reject_tmptab++;
1943
1975
        DBUG_PRINT("qcache",
1944
1976
                   ("Temporary table detected: '%s.%s'",
1945
1977
                    tmptable->s->db.str, tmptable->alias.c_ptr()));
1961
1993
#ifndef NO_EMBEDDED_ACCESS_CHECKS
1962
1994
    if (check_table_access(thd,SELECT_ACL,&table_list, 1, TRUE))
1963
1995
    {
 
1996
      reject_noacc++;
1964
1997
      DBUG_PRINT("qcache",
1965
1998
                 ("probably no SELECT access to %s.%s =>  return to normal processing",
1966
1999
                  table_list.db, table_list.alias));
1971
2004
    }
1972
2005
    if (table_list.grant.want_privilege)
1973
2006
    {
 
2007
      reject_noacc++;
1974
2008
      DBUG_PRINT("qcache", ("Need to check column privileges for %s.%s",
1975
2009
                            table_list.db, table_list.alias));
1976
2010
      BLOCK_UNLOCK_RD(query_block);
1984
2018
                              table->key_length(),
1985
2019
                              &engine_data))
1986
2020
    {
 
2021
      reject_engine++;
1987
2022
      DBUG_PRINT("qcache", ("Handler does not allow caching for %s.%s",
1988
2023
                            table_list.db, table_list.alias));
1989
2024
      BLOCK_UNLOCK_RD(query_block);
2757
2792
    {
2758
2793
      // removing unfinished query
2759
2794
      refused++;
 
2795
      refused_abrt++;
2760
2796
      inserts--;
2761
2797
    }
2762
2798
    Query_cache_block *block= result_block;
2771
2807
  {
2772
2808
    // removing unfinished query
2773
2809
    refused++;
 
2810
    refused_abrt++;
2774
2811
    inserts--;
2775
2812
  }
2776
2813