RE: Bad plan selected at the beginning of the month for partitioned table

From: <Jay.Miller_at_tdameritrade.com>
Date: Thu, 1 Feb 2018 17:25:45 +0000
Message-ID: <0D8F4CAC0F9D3C4AACC63F50FD9957F75479284A_at_PRDCTWPEMLMB31.prod-am.ameritrade.com>



Yes, it would be nice if I could tell the developers to alter their code. Unfortunately it isn’t an option here. Not least because all the developers who wrote the code have left the company and the new people are scared to touch it.

Jay Miller
Sr. Oracle DBA
201.369.8355

From: Carlos Sierra [mailto:carlos.sierra.usa_at_gmail.com] Sent: Thursday, February 01, 2018 11:38 AM To: Miller, Jay
Cc: oracle-l_at_freelists.org
Subject: Re: Bad plan selected at the beginning of the month for partitioned table

Jay,

I would go with: keeping the same SQL_ID and SIGNATURE, and have a SQL Plan Baseline on the new SQL.

COL column1 HEA 'January 2018 Totals';
SELECT column1, column2…

Cheers — Carlos

On Feb 1, 2018, at 07:29, Jay.Miller_at_tdameritrade.com<mailto:Jay.Miller_at_tdameritrade.com> wrote:

Hello everyone,

I'm currently battling an annoying problem and was hoping someone had a better solution than the one I came up with.

One of our databases has 2 frequent queries that run against a partitioned table. At the beginning of the month when the partition is empty they start doing a full partition scan instead of an index range scan (no surprise). However even after rows start being loaded to the partition and stats are gathered that night the plan does not change back. I have verified that the stats have been updated, numrows is populated, and the stats do not show as stale. But even after 3 days the bad plan continues to be used and app performance gets so poor that I manually purge the sql_id from the shared pool. It then reverts to the index range scan and everything is fine.

When I first encountered the problem I thought it was an easy fix, I'd just create a baseline. Unfortunately I then discovered that the text of the sql changes each month to give a month specific alias. E.g., something like select column1 "January 2018 Totals", column2... So the sql_id is different each month and any baselines or profiles will not be used. Also because of this I can't easily schedule a job to purge the plan. I'd don’t want to schedule a job to flush the entire shared pool at the beginning of the month due to performance issues when everything is reparsed and the possibility of a bad plan being chosen somewhere else.

Barring any of you suggesting a more elegant suggestion I intend to precreate a few years’ worth of partitions, copy stats from a current partition, and then lock them. I’ll put an Outlook reminder to do the same in a few years and hope I’m either still with the company or remember to pass this piece of lore down when I leave.

Any better ideas he asked hopefully?

Oracle 11.2.0.3 on RH 6.

TIA,
Jay Miller
Sr. Oracle DBA

--
http://www.freelists.org/webpage/oracle-l
Received on Thu Feb 01 2018 - 18:25:45 CET

Original text of this message