{"id":3472,"date":"2025-05-23T09:02:23","date_gmt":"2025-05-23T09:02:23","guid":{"rendered":"https:\/\/w3buddy.com\/?p=3472"},"modified":"2026-01-15T12:44:18","modified_gmt":"2026-01-15T07:14:18","slug":"why-fast-queries-suddenly-slow-down-and-what-causes-execution-plan-changes-in-oracle","status":"publish","type":"post","link":"https:\/\/w3buddy.com\/blog\/why-fast-queries-suddenly-slow-down-and-what-causes-execution-plan-changes-in-oracle\/","title":{"rendered":"Why Fast Queries Suddenly Slow Down \u2014 And What Causes Execution Plan Changes in Oracle"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Have you ever run a SQL query that used to be lightning-fast\u2026 and now it crawls?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The likely culprit? <strong>The Execution Plan Changed.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As an Oracle DBA or developer, understanding <strong>why execution plans change<\/strong> is crucial for diagnosing and preventing performance regressions. Let\u2019s walk through the <strong>common causes<\/strong> of plan changes, how they impact performance, and what you can do about them \u2014 explained simply, just like your favorite teacher would.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd0d First, What Is an Execution Plan?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Think of an execution plan as Oracle\u2019s <strong>game plan<\/strong> for retrieving your data. When you run a SQL query, Oracle\u2019s optimizer decides <strong>how<\/strong> to access the data: which indexes to use, in what order to join tables, whether to do a full scan, and so on.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But here\u2019s the catch \u2014 this plan can change. And when it does, it might not be for the better.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83c\udf00 When and Why Do Execution Plans Change?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s explore the most common scenarios, what causes them, and what you \u2014 as a DBA or developer \u2014 should do.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1\ufe0f\u20e3 <strong>Statistics Change<\/strong><\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\ud83d\udcca <em>&#8220;Your data changed, so Oracle adapts its plan.&#8221;<\/em><\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">Oracle relies on <strong>table and index statistics<\/strong> to estimate how much data a query will return. If these stats change significantly (e.g., table grows, data distribution changes), Oracle may choose a different access path.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Common Cause<\/strong>: Running DBMS_STATS or auto-gather stats job.<\/li>\n\n\n\n<li><strong>Example<\/strong>: A small table became large, so Oracle switches from an index scan to a full table scan.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\ud83d\udc68\u200d\ud83c\udfeb Tip for DBAs<\/strong>:<br>After gathering stats, always <strong>validate execution plans<\/strong> for critical queries.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2\ufe0f\u20e3 <strong>Schema Changes (Indexes, Partitions, Constraints)<\/strong><\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\ud83c\udfd7\ufe0f <em>&#8220;You added or removed a structure \u2014 Oracle re-evaluates the path.&#8221;<\/em><\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">Any DDL change can influence how Oracle thinks about a query.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Common Changes<\/strong>: Creating or dropping indexes, adding partitions, adding foreign keys or not null constraints.<\/li>\n\n\n\n<li><strong>Impact<\/strong>: Optimizer might prefer a new path because more options are now available.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\ud83d\udc68\u200d\ud83c\udfeb Tip for DBAs<\/strong>:<br>After any schema-level DDL, <strong>review impacted queries<\/strong> using tools like SQL Tuning Advisor or manual plan comparisons.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3\ufe0f\u20e3 <strong>Bind Peeking and Data Skew<\/strong><\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\ud83c\udfaf <em>&#8220;The first value matters more than you think.&#8221;<\/em><\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">When a query uses <strong>bind variables<\/strong>, Oracle &#8220;peeks&#8221; at the actual bind value during the first hard parse. If the value is unusual (e.g., rare), Oracle may pick a plan that isn\u2019t good for typical values.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Example<\/strong>: Querying WHERE country = :1. The first run is with &#8220;Iceland&#8221; (few rows), Oracle chooses index access. Later you run it with &#8220;USA&#8221; (millions of rows) \u2014 and the same plan now performs poorly.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\ud83d\udc68\u200d\ud83c\udfeb Tip for DBAs<\/strong>:<br>Watch out for <strong>data skew<\/strong>. Use <strong>SQL Plan Management<\/strong> or <strong>Adaptive Cursor Sharing<\/strong> if needed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4\ufe0f\u20e3 <strong>System or Optimizer Parameter Changes<\/strong><\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u2699\ufe0f <em>&#8220;Changed settings = changed behavior.&#8221;<\/em><\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">Oracle\u2019s optimizer behavior is influenced by many parameters like:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>optimizer_mode<\/li>\n\n\n\n<li>optimizer_features_enable<\/li>\n\n\n\n<li>_optimizer_use_feedback<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Changes can come from patching, upgrades, or direct parameter edits.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\ud83d\udc68\u200d\ud83c\udfeb Tip for DBAs<\/strong>:<br>After upgrades or patching, <strong>compare execution plans<\/strong>. Maintain test environments to spot surprises early.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5\ufe0f\u20e3 <strong>Plan Aged Out of Shared Pool<\/strong><\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u23f3 <em>&#8220;If it&#8217;s gone from memory, Oracle makes a new choice.&#8221;<\/em><\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">Execution plans live in the <strong>shared pool<\/strong>. If Oracle needs memory and removes an old plan, it re-parses the query next time \u2014 and might pick a different path.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Cause<\/strong>: Memory pressure, infrequent query usage.<\/li>\n\n\n\n<li><strong>Risk<\/strong>: New plan might not match the old one&#8217;s performance.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\ud83d\udc68\u200d\ud83c\udfeb Tip for DBAs<\/strong>:<br>Use tools like <strong>AWR<\/strong>, <strong>ASH<\/strong>, or <code>DBMS_XPLAN.DISPLAY_CURSOR<\/code> to track <code>plan_hash_value<\/code>. Consider using <strong>SQL Plan Baselines<\/strong> to \u201clock\u201d good plans.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 What Can You Do to Prevent Bad Plan Changes?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udd12 <strong>Use SQL Plan Baselines<\/strong><br>They help \u201clock in\u201d a known-good plan, so Oracle doesn\u2019t surprise you.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udcc8 <strong>Monitor Plan Stability<\/strong><br>Regularly track <code>plan_hash_value<\/code> changes for your top queries.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83e\uddea <strong>Test Before You Change<\/strong><br>Always test performance after applying patches, running stats, or making schema changes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udcda In Summary<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Execution plans are not static \u2014 they evolve. That\u2019s both a strength and a challenge. Knowing <em>when and why<\/em> plans change helps you:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Prevent slowdowns<\/li>\n\n\n\n<li>Fix regressions quickly<\/li>\n\n\n\n<li>Be proactive, not reactive<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Next time a user says, <em>&#8220;Hey, this query used to be faster!&#8221;<\/em> \u2014 you\u2019ll know exactly where to look.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udcac <strong>Have a question about execution plans? Share your scenario \u2014 let&#8217;s troubleshoot together!<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever run a SQL query that used to be lightning-fast\u2026 and now it crawls? The likely culprit? The Execution Plan Changed. As an Oracle DBA or developer, understanding why execution plans change is crucial for diagnosing and preventing performance regressions. Let\u2019s walk through the common causes of plan changes, how they impact performance, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"googlesitekit_rrm_CAowu461DA:productID":"","footnotes":""},"categories":[1225],"tags":[],"class_list":["post-3472","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/3472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/comments?post=3472"}],"version-history":[{"count":1,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/3472\/revisions"}],"predecessor-version":[{"id":3474,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/3472\/revisions\/3474"}],"wp:attachment":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=3472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=3472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/tags?post=3472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}