Questions tagged [query-cache]

Query Cache is the cache, that stores the database queries and their results.

Query Cache is a cache of database queries and their associated results, so next time the result can be returned immediately.

Such cache is often implemented in the database itself (like MySQL) or in the ORM system (like Hibernate) to improve overall performance.

151 questions
35
votes
11 answers

Why does an insert query occasionally take so long to complete?

This is a pretty simple problem. Inserting data into the table normally works fine, except for a few times where the insert query takes a few seconds. (I am not trying to bulk insert data.) So I setup a simulation for the insert process to find out…
Daniel
  • 7,006
  • 7
  • 43
  • 49
14
votes
3 answers

Very slow: ActiveRecord::QueryCache#call

I have an app on heroku, running on Puma: workers 2 threads_count 3 pool 5 It looks like some requests get stuck in the middleware, and it makes the app very slow (VERY!). I have seen other people threads about this problem but no solution so…
user3029400
  • 387
  • 1
  • 5
  • 13
10
votes
2 answers

Yii2: How to cache queries made by ActiveRecord relations

I have news table and its related news_comment table. I have defined relation newsComment with news_comment table. If I execute this query: $result = News::getDb()->cache(function () use($id) { return…
offline
  • 1,589
  • 1
  • 21
  • 42
10
votes
3 answers

Hibernate query cache - for objects not in the 2nd level cache - risky? useful? bad practice?

Related to this question Premise: These are my assumptions, based on my reading, experience and understanding, they may be wrong, if they are, please comment and I'll edit the question. Query cache is good mostly along with 2nd level cache Query…
Eran Medan
  • 44,555
  • 61
  • 184
  • 276
8
votes
3 answers

How to flush db query cache in yii2?

How to handle it when some changes happen in specific table records ? public static function getAirportWithCache($iata_code){ $result = Airports::getDb()->cache(function ($db) use ($iata_code){ $res =…
Yatin Mistry
  • 1,246
  • 2
  • 13
  • 35
7
votes
4 answers

mysql 5.7 is much slower than mysql 5.6 in medium sql

We are upgrading to mysql 5.7 and just discover that it is much slower than its 5.6 counter part. While both have almost identical config, the 5.6 version execute most of the sqls in milliseconds, while the other takes around 1 sec or more for a…
Phung D. An
  • 2,402
  • 1
  • 22
  • 23
6
votes
3 answers

MySQL cache and date functions

I once read in a performance blog that it is better to use PHP's date functions to set dates in a MySQL query instead of using mysql date functions like curdate() because mysql can then cache the query or the result or something like that. Does…
dqhendricks
  • 19,030
  • 11
  • 50
  • 83
6
votes
1 answer

How to use ActiveRecord Query Cache with Custom SQL

In a stats part of a Rails app, I have some custom SQL calls that are called with ActiveRecord::Base.execute() from the model code. They return various aggregates. Some of these (identical) queries are run in a loop in the controller, and it seems…
Christopher Foy
  • 758
  • 5
  • 13
6
votes
3 answers

View mysql query cache contents

I have a large database application that uses mysqls query cache ability. I'd like to inspect the contents of the query cache to identify entries that should not get cached (e.g. by using SELECT SQL_NO_CACHE...) because I want to optimize my…
maxhb
  • 8,554
  • 9
  • 29
  • 53
6
votes
3 answers

Hibernate Second-Level Query Cache not working Eager Fetching

In NHibernate Profiler I observed that when I use eager fetching on an association, using "left join fetch" in an HQL Query or .SetFetchMode() in a Criteria Query the query no longer gets cached in the query cache. In fact from what I can see only…
reach4thelasers
  • 26,181
  • 22
  • 92
  • 123
6
votes
2 answers

MySQL flush query cache

I have a slow database query that runs 18 seconds for the first run and 4 seconds as any subsequent run. I am trying to optimize it's "coldstart" execution time. But not able to reproduce it continuously. select SQL_NO_CACHE directive doesn't…
Bogdan Gusiev
  • 8,027
  • 16
  • 61
  • 81
6
votes
3 answers

How to enable hibernate query cache on a session level only?

What if I have a query that gets called multiple times in a single thread, and I just want to cache that query (and its result) for that thread (or for that session since I'm using one session per thread), how can I do that ? Note: My 2nd level…
Franz See
  • 3,282
  • 5
  • 41
  • 48
6
votes
2 answers

Using the same MySQL query with all users without having to reconnect to the database

I'll try to be simple, so what i need is, perform a MySQL query (selecting records from a table) let's say ill produce the query with cron jobs or whatever every 5 minutes, and save this query or results to a file or a global variable if it's…
user1852196
  • 127
  • 2
  • 2
  • 10
5
votes
1 answer

occasional slow UPDATE using primary key

I have an InnoDB table in MySQL 5.5.53 where simple updates like UPDATE mytable SET acol = 'value' WHERE id = 42; hang for several seconds. id is the primary key of the table. If I enable query profiling using SET profiling = 1; then run the query…
Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
5
votes
0 answers

Enabling query-caching with CriteriaQuery. Is this possible?

I want to enable hibernate query cache. I understand 'Query' and 'Criteria' has a function called 'setCachable' in order to mark the query as cacheable. Is there a way to do this with 'CriteriaQuery'? CriteriaQuery criteria =…
user459811
  • 2,874
  • 10
  • 37
  • 63
1
2 3
10 11