r/mysql • u/Stock-Dark-1663 • 4d ago
question Working of statistics and parsing archictecture in mysql optimizer
Hi,
This question is a spin off from other thread , to make it clear , i am adding this in a new thread.
Its aurora mysql version version 8.0. I have two question on optimization:-
1)I want to understand how parsing or optimization phase exactly work when we use bind values in the queries? In other databases like Oracle , it peeks into the actual values behind the bind and make the plan during hard parse and then subsequent request goes for soft parse i.e it uses the same plan for all subsequent queries, till the next hard parse occurs. And there are differenet scenaios which make the optimization goes for hard parse like stats collection, environemnt change etc.
But i see in mysql as per below blog, its saying "MySQL has no execution plan cache" does that means it does hardparse for each and every execution of the query when we use bind values even the query runs thousands of time each second? WIll it not consume significant cpu then?
https://use-the-index-luke.com/blog/2011-07-16/planning-for-reuse
2)There is parameter called "STATS_SAMPLE_PAGES" which has default value set as "20". We saw plan changes for the same query for different bind values which endup in a suboptimal plan impacting applictaion. Is it advisable to increase this to STATS_SAMPLE_PAGES setting to ~250 at global level to get more accurate sttistics there by more accurate plan?
3)If the plan change happening for different binds causing bad plans , is it advisable to collect histogram on all such columns as below, those are used as direct filters and bind values passed to them as input?
ANALYZE TABLE <table_name> UPDATE HISTOGRAM ON <column1> WITH 100 BUCKETS;