Tuesday, October 29, 2024
Something fun to do, a word search!!
Friday, September 13, 2024
Cloud World 24 - done!
I had a good time at Cloud World, except for leaving my iPhone in the Uber car Tuesday morning. That was not fun! Took quite awhile and a lot of effort to get it back. I don't recommend doing that.
The presentation went very well. There were over 350 folk register for the presentation, I'm not sure how many showed up. Likely approaching 200, defiantly serious overflow for the area we had for the presentation.
It was great to catch up with a few friends, I know more folks were there I wanted to see but it was such a huge event it was hard to find folks.
Here are a few fun photos.
Tuesday, August 13, 2024
Cloud World 2024
Hey! I’ll be presenting at Cloud World this year! Woot-woot! I think the last time I was at this event it was still called Open World and it was still in San Francisco. Yea been a while.
Improve Custom BIP Reports: from Hours to Minutes [THR2938]
Wednesday, Sep 11, 1:50 PM - 2:10 PM PDT
And yes, I’ll get to talk about my favorite topic, CTEs!!
If you happen to be going to this spectacular event, stop by and say Hi!
Friday, April 12, 2024
EXISTS vs EQUALITY - sand in the gears
The best thing about doing SQL Optimization is there is always something that needs attention.
FROM big_tab bigtab
WHERE 1 = ( SELECT 1 FROM allusers_tab alluserstab
WHERE bigtab.owner = alluserstab.username
and rownum = 1 );
| Id | Operation | Name |
--------------------------------------------------
| 0 | SELECT STATEMENT | |
|* 1 | FILTER | |
| 2 | TABLE ACCESS STORAGE FULL| BIG_TAB |
|* 3 | COUNT STOPKEY | |
|* 4 | INDEX UNIQUE SCAN | USERNAME_PK |
--------------------------------------------------
FROM big_tab bigtab
WHERE EXISTS ( SELECT 1 FROM allusers_tab alluserstab
WHERE bigtab.owner = alluserstab.username
| Id | Operation | Name |
--------------------------------------------------
| 0 | SELECT STATEMENT | |
|* 1 | HASH JOIN | |
| 2 | INDEX FULL SCAN | USERNAME_PK |
| 3 | TABLE ACCESS STORAGE FULL| BIG_TAB |
--------------------------------------------------
Doing the Equality check 1000 times:
Times in hundredths of a second
**** TIME - 25195
**** CPU - 24653
Doing the EXISTS (without ROWNUM=1) 1000 times:
**** TIME - 20090
**** CPU - 19790
= = = = = = = = = = = = = = = = = = = = = = = = = = = = =
DECLARE
l_start_time pls_integer;
l_start_cpu pls_integer;
Cursor test_cur01 is
select count(*) from (
SELECT OWNER, OBJECT_NAME, OBJECT_TYPE
FROM big_tab bigtab
WHERE 1 = ( SELECT 1 FROM allusers_tab alluserstab
WHERE bigtab.owner = alluserstab.username
and rownum = 1 ) );
Cursor test_cur02 is
select count(*) from (SELECT OWNER, OBJECT_NAME, OBJECT_TYPE
FROM big_tab bigtab
WHERE Exists ( SELECT 1 FROM allusers_tab alluserstab
WHERE bigtab.owner = alluserstab.username));
cur01_rec test_cur01%rowtype;
cur02_rec test_cur02%rowtype;
BEGIN
l_start_time := DBMS_UTILITY.GET_TIME;
l_start_cpu := DBMS_UTILITY.GET_CPU_TIME;
for i in 1 .. 1000 loop
open test_cur01;
fetch test_cur01 into cur01_rec;
close test_cur01;
end loop;
DBMS_OUTPUT.put_line ('Times in hundredths of a second');
DBMS_OUTPUT.put_line ('**** TIME - '||to_char(DBMS_UTILITY.get_time - l_start_time));
DBMS_OUTPUT.put_line ('**** CPU - '||to_char(DBMS_UTILITY.GET_CPU_TIME - l_start_cpu));
l_start_time := DBMS_UTILITY.GET_TIME;
l_start_cpu := DBMS_UTILITY.GET_CPU_TIME;
for i in 1 .. 1000 loop
open test_cur02;
fetch test_cur02 into cur02_rec;
close test_cur02;
end loop;
DBMS_OUTPUT.put_line ('Times in hundredths of a second');
DBMS_OUTPUT.put_line ('**** TIME - '||to_char(DBMS_UTILITY.get_time - l_start_time));
DBMS_OUTPUT.put_line ('**** CPU - '||to_char(DBMS_UTILITY.GET_CPU_TIME - l_start_cpu));
END;
/
Wednesday, January 17, 2024
A misunderstanding about the Materialize hint
I think I have found out why some folks are resisting using this hint when defining a CTE (Common Table Expression). There apparently is a misunderstanding about what this hint does.
This doesn’t cause the CTE to be kept in memory (the PGA) after the query finishes. This only forces the optimizer to not “merge” it back into the main query. A materialized CTE will store the results set in a GTT (Global Temp Table) like structure during the run of the statement. This GTT is dropped once the query finishes.
I say again, the GTT is dropped and is not kept in the PGA once the query finishes.
So, what does the hint do and why do I recommend using it pretty much all the time?
What it does is force the optimizer to keep the CTE as a separate unit and not merge (refactor) it back into the main query. Generally merging the CTE back into the query is not what we want to have happen. We just spent all this time and effort to write the code with a CTE and then the optimizer negates all that work.
I can count on one hand the number of times that the materialize hint made a query worse. Sometimes it doesn’t matter, the optimizer will materialize a CTE with or without the hint. For example, if the CTE is referenced more than one time, the optimizer will automatically materialize the CTE.
One more time, with feeling, the GTT used during the run of a query for a materialized CTE is DROPPED after the statement finishes.
I have several blog posts raving about all the wonderful things a CTE can do to make queries run better faster and stronger. Please see these for ideas on how you can use them to speed up your code.