Comments on: Auto caching tables https://shlomi-noach.github.io/blog/mysql/auto-caching-tables Blog by Shlomi Noach Thu, 08 Mar 2012 18:33:08 +0000 hourly 1 https://wordpress.org/?v=5.3.3 By: Auto caching INFORMATION_SCHEMA tables: seeking input | code.openark.org https://shlomi-noach.github.io/blog/mysql/auto-caching-tables/comment-page-1#comment-74914 Thu, 08 Mar 2012 18:33:08 +0000 https://shlomi-noach.github.io/blog/?p=4353#comment-74914 […] Auto caching tables […]

]]>
By: shlomi https://shlomi-noach.github.io/blog/mysql/auto-caching-tables/comment-page-1#comment-74328 Wed, 07 Mar 2012 12:10:18 +0000 https://shlomi-noach.github.io/blog/?p=4353#comment-74328 @Jannes,
Thanks

1. Yes, indeed.
2. True, though the above is merely a demo. You may wish to only invalidate specific rows
3. Yes and no. You can use this_query() to get the invocating query. If you’re up to parsing it, well, it can be done.

]]>
By: Jannes https://shlomi-noach.github.io/blog/mysql/auto-caching-tables/comment-page-1#comment-74284 Wed, 07 Mar 2012 09:46:59 +0000 https://shlomi-noach.github.io/blog/?p=4353#comment-74284 Wow nice! I’ve been trying to attack this problem from similar sides a few times as well, but hadn’t made it fit together so nicely!

1) I guess you could let your function return a 1 in case the cache was just freshly revalidated? Or a timestamp of the last revalidation and then the client running the query could SELECT that field as well if it were interested in that information?

2) A TRUNCATE would be faster than DELETE FROM cache_sample_data; right? (IF you want to delete everything). Of course you could have logic that allows you to update only what has changed since the previous revalidation.

3) I guess it’s not possible to ONLY revalidate rows that the client is interested in (i.e. the rest of the WHERE clause in the client’s query) ?

Anyway, congrats for pulling this off!

]]>
By: shlomi https://shlomi-noach.github.io/blog/mysql/auto-caching-tables/comment-page-1#comment-74130 Tue, 06 Mar 2012 20:49:55 +0000 https://shlomi-noach.github.io/blog/?p=4353#comment-74130 @Rick,
I’m utterly not sold on “The Query cache does an even better job of optimizing that case”, for many reasons.
One being that the query cache results get invalidated so frequently, and by such innocent updates, that it quickly becomes useless. At least this is my experience.

I agree that the stored routine makes for an overhead. MySQL is very slow in interpreting stored routines.

The RAND is only used because it’s simplest to demonstrate with, and easiest to follow. It does not make sense to use RAND for real. Thus, the “10% of the time it will be even slower” is irrelevant. It should be “Once every #### times the query is even slower than it would without cache”.

]]>
By: Rick James https://shlomi-noach.github.io/blog/mysql/auto-caching-tables/comment-page-1#comment-74124 Tue, 06 Mar 2012 20:41:13 +0000 https://shlomi-noach.github.io/blog/?p=4353#comment-74124 As I see it (and using the RAND), 10% of the time it will be even slower than the underlying query. If this is in a UI, the user will get unpredictable response time (not good).

OTOH, in a batch job, it would (could) cut down on overall system load and, on average, speed up the process.

If the RAND is replaced by some _cheap_ test for whether to refresh the cache, _and_ refreshing is costly, then “you pay the price only when you need to”. — this has applicability. But that implies that the SELECT is happening more often than changes to the underlying table. Guess what? The Query cache does an even better job of optimizing that case.

If there is a WHERE clause on the user’s query, that is not, and can not, be pushed down to the reload subquery. If it could, that would open up more doors for optimizations.

Maybe I will find a use for this eventually. It is quite clever!

]]>
By: Giuseppe Maxia https://shlomi-noach.github.io/blog/mysql/auto-caching-tables/comment-page-1#comment-74038 Tue, 06 Mar 2012 16:13:57 +0000 https://shlomi-noach.github.io/blog/?p=4353#comment-74038 Congratulations on yet another great hack!

]]>
By: shlomi https://shlomi-noach.github.io/blog/mysql/auto-caching-tables/comment-page-1#comment-74013 Tue, 06 Mar 2012 15:27:20 +0000 https://shlomi-noach.github.io/blog/?p=4353#comment-74013 @Roland,
My next post will discuss INFORMATION_SCHEMA. I have this working, but am unsatisfied with a few issues.

@Jonathan,
Take time-based invalidation, which is commonly used, such with memcached. Data is valid for the next 5 minutes. Put the readtime somewhere.
It’s simple, yet surprisingly useful, in my opinion.

]]>
By: Jonathan Levin https://shlomi-noach.github.io/blog/mysql/auto-caching-tables/comment-page-1#comment-74002 Tue, 06 Mar 2012 14:59:19 +0000 https://shlomi-noach.github.io/blog/?p=4353#comment-74002 Hi Sholmi,

I like the idea, but I have a bad feeling about it from past experiences.
A lot depends on the cache invalidation heuristic you pointed out. If it is inefficient, you just have a lot of IO overhead where it was not needed.

Can you recommend some good cache invalidation techniques to go with this idea?

]]>
By: Roland Bouman https://shlomi-noach.github.io/blog/mysql/auto-caching-tables/comment-page-1#comment-73997 Tue, 06 Mar 2012 14:39:02 +0000 https://shlomi-noach.github.io/blog/?p=4353#comment-73997 Hi Shlomi!

Brilliant solution 🙂

There’s a lot of moving parts but I think this is going to be worth it if we can get better information_schema performance and reliability with this.

]]>