Why does dynamic sampling lead to incorrect execution plans?
A new table is created every month to store log information, with about 200 million data per month. The table is named EVENT_USAGE_<YYYYMM>.
Example: EVENT_USAGE_202407 EVENT_USAGE_202408 EVENT_USAGE_202409 Statistics were collected for the tables in August and September, when there was no data on these tables.
It was never collected again Statistics. EVENT_USAGE_202408 query is fine in August, execution plan can use index.
The statistics for table EVENT_USAGE_202409 were deleted in August, and in September, the query for table EVENT_USAGE_202409 appeared
Because of performance problems, the execution plan is changed to full table scan (the execution plan is dynamic statistics used: dynamic sampling (level=2)).