Articles Comments

Oracle DBA & All IT » New Feature, Oracle Tips, Tuning Performance » การสร้าง Outline บังคับให้ statement ใช้ index ตามที่เราต้องการ

การสร้าง Outline บังคับให้ statement ใช้ index ตามที่เราต้องการ

บ่อยๆ ที่เราจะพบว่า statement ช้าก่อน พอ Plan table ดูกลับพบว่า ใช้ index ไม่ถูกตัวแต่ไม่อยากที่จะแก้โปรแกรมโดยการใส่ hint ตอนนี้เราสามารถที่จะใช้ outline มาแก้ปัญหานี้ได้โดยสร้าง outline

outline คืออะไร คือเป็นตัวบอกว่า statment นี้ถ้าเข้ามาให้ไปใช้ plan ตามที่เราเตรียมไว้นั่นเอง
 

           สร้าง outline เพื่อให้เวลาที่โปรแกรมรันด้วย statement original ไปใช้ plan เหมือนกับที่เรา force index ค่ะ

Replace ชื่อตามที่ highlight สีชมพูค่ะ แก้ statement ตามตัวสีแดง นอกนั้นไม่ต้องแก้อะไรค่ะ เมื่อลอง plan ดูจะเห็นว่า statement นั้น plan เปลี่ยนไปแล้วค่ะ

/*สำหรับ statement original*/
CREATE OR REPLACE OUTLINE TEST1 ON
SELECT MAX (a.event_dtm)
FROM costedevent a
WHERE a.account_num = :b1

/

/*สำหรับ statement ที่ force index*/
create or replace outline TEST1HINTSQL on
SELECT /*+ index_ss(a,costedevent_pk) */ MAX (a.event_dtm)
FROM costedevent a
WHERE a.account_num = :b1

/

/* สำหรับ Update plan ที่ hint ให้เป็น plan ของ original statement*/
UPDATE OUTLN.OL$HINTS
SET OL_NAME=DECODE(OL_NAME,'TEST1HINTSQL','TEST1','TEST1','TEST1HINTSQL')
WHERE OL_NAME IN ('TEST1','TEST1HINTSQL');
COMMIT;

/* สำหรับ Drop outline TEST1HINTSQL ทิ้งไป เพราะเรามีการ Update Plan เป็น TEST1 เรียบร้อย*/
drop outline TEST1HINTSQL;

/* สำหรับ นำ outline TEST1 ไปอยู่ใน Category ชื่อ CAT_1*/
alter outline TEST1change category to CAT_1;

/* Parameter ที่ต้อง Set ถ้าต้องการให้ระบบใช้ Outline ที่เราสร้าง*/
ALTER system SET USE_STORED_OUTLINES = TRUE;
alter system set use_stored_outlines=CAT_1;

Tips!
เมื่อมีการ restart DB ค่าที่เรา set USE_STORED_OUTLINES,use_stored_outlines  ไว้จะหายต้องทำการ Alter ใหม่ แต่เรามีวิธีให้มันทำทุกครั้งที่ Restart DB ได้ โดยการไปผูก Trigger ไว้ตอนที่ Startup DB โดยสร้างด้วย user SYS

CREATE OR REPLACE TRIGGER enable_outlines_trig
after startup on database
begin
execute immediate('alter system set use_stored_outlines=true');
execute immediate('alter system set use_stored_outlines=CAT_1');
end;
/

ลองไปทำกันดูนะคะ ^^

.. Preview : 30427

Related Search:

  • outline คือ
  • การเขียน outline
  • การเขียนoutline
  • ตัวอย่างการเขียน outline
  • outline คืออะไร

Written by

บอกเล่าสิ่งที่พบเจอมาในการทำงาน ประสบการณ์การทำงานด้าน DBA ถ่ายทอดกันด้วยภาษาง่ายๆ บ้านๆ " ทุกอย่างไม่อยาก แต่... แค่ตั้งใจไม่พอ ต้องลงมือทำ และทำ GoodLuck " Fanpage: www.facebook.com/DBAor .. "Oracle Database Consultant " ..

Filed under: New Feature, Oracle Tips, Tuning Performance · Tags: , , , , , ,

  • Like the modern layout. I was pleased with this content. Appreciation for the superb entry.

  • The devil takes the hindmost.

  • Honesty is the best policy.

    • Ho ho, who wdolua thunk it, right?

    • This is way more hlpuefl than anything else I’ve looked at.

  • Numz

    But for 11g, we can use SQL Plan baseline new feature instead of outline 🙂

  • The laugh is always on the loser.

  • Insightful site=D I am going to take a decent amount of time to think about this website.

    • Whoa, thngis just got a whole lot easier.

    • You’re the one with the birnas here. I’m watching for your posts.

  • Hey there, just wanted to drop you a quick line to say that your post was interesting to read. Cheers

    • Frankly I think that’s absloutley good stuff.

    • Hahhaaha. I’m not too bright today. Great post!

  • Sweet internet site , super design , rattling clean and apply pleasant.

    • Umm, are you really just giving this info out for ntoihng?

  • Good day. i am doing research right now and your blog really helped me,    

    • Great thinking! That rlaely breaks the mold!

    • Frnakly I think that’s absolutely good stuff.

  • TYVM you’ve solved all my pbroelms

  • That’s really shewrd! Good to see the logic set out so well.