Oracle Scratchpad

January 31, 2010

PCTFREE

Filed under: Infrastructure — Jonathan Lewis @ 6:32 pm UTC Jan 31,2010

If you’ve ever struggled with setting PCTFREE for a table, there’s a nice post on OTN from Anurag Tibrewal which should help you understand what you’re trying to achieve, and recognise the trade-off between wasting space and reducing row migration.

January 30, 2010

Free Space

Filed under: fragmentation,Infrastructure,Oracle — Jonathan Lewis @ 10:37 am UTC Jan 30,2010

I’ve just seen the following question on OTN:

I had a log table which was about 30G in Production, since it was growing in size we decided to drop it. After dropping it we can’t see the space being freed. Even at OS level we can’t see any reduction in filesize.Can you please explain and/or help in this?

This prompted me to come up with the following analogy. (more…)

January 27, 2010

Plan Notes

Filed under: dbms_xplan — Jonathan Lewis @ 7:07 pm UTC Jan 27,2010

Nothing terribly important or exciting in this post, but you’ve probably seen the “Notes” section at the end of an execution plan from time to time. The notes are extracted from the “other_xml” column of (usually) the first line of the execution plan data using calls to the extractvalue() XML function.

It’s interesting to see from a trace of a call to dbms_xplan.display_cursor() how the number of things that can appear as notes is slowly growing over recent versions of Oracle. The statements below are extracted from the trace files for 10.2.0.3, 11.1.0.6, and 11.2.0.1 in that order: (more…)

January 26, 2010

Aliases

Filed under: Infrastructure — Jonathan Lewis @ 6:45 pm UTC Jan 26,2010

I was asked the following question recently: “Does the use of table aliases affect performance?” To which the best answer is probably “Yes, though in general you probably won’t notice the difference and there are reasons more important than performance for using table aliases.”

Consider the following two variants of a simple SQL statement: (more…)

January 25, 2010

Old plan_table

Filed under: dbms_xplan — Jonathan Lewis @ 8:27 am UTC Jan 25,2010

When using “explain plan” with “dbms_xplan.display()”, have you ever seen the following note at the end of the output:

Note
-----
   - 'PLAN_TABLE' is old version

It’s something I see surprisingly frequently, travelling as I do to many different sites, but it’s usually easy to deal with. (more…)

January 14, 2010

Old ideas

Filed under: Indexing,Troubleshooting — Jonathan Lewis @ 6:57 pm UTC Jan 14,2010

Here’s a question about function-based indexes that appeared a little while ago on OTN, demonstrating the problems of old information not going away. This is how the question started: (more…)

January 12, 2010

force_match

Filed under: Infrastructure,Performance — Jonathan Lewis @ 7:19 pm UTC Jan 12,2010

If you have looked at SQL Profiles (see for example Kerry Osborne’s blog) then you may have come across the force_match option for enabling or importing a SQL profile. I received an email recently asking a few questions about this feature. (more…)

January 10, 2010

first_rows_N again

Filed under: CBO,Performance,Tuning — Jonathan Lewis @ 7:02 pm UTC Jan 10,2010

If you run a query using first_rows_N optimisation you could run into a massive performance problem in cases where the optimizer thinks the complete result set is quite large when it is actually very small.

If both conditions are true the optimizer may choose a very resource-intensive execution path “expecting” to stop (or at least pause between fetches) after N rows – hoping to give the impression that it can respond very quickly – but find that the query has to run to completion because the N rows simply don’t exist.

(more…)

January 7, 2010

Testing, Testing

Filed under: Troubleshooting — Jonathan Lewis @ 7:41 pm UTC Jan 7,2010

Here’s a request that appeared on the OTN database forum recently:

I fetch reports in our Oracle 9i database each year between 9/1 to 8/31:

Each year I always have to manually change my sql and was wondering if there is a way to fetch the records between 9/1 to 8/31 without changing the year.

For example this will be my query for this year from 9/1/2009 to 8/31/2010:

SELECT  *
FROM    emp
WHERE   HIREDATE between to_date ('2009/09/01', 'yyyy/mm/dd')
                     AND to_date ('2010/08/31', 'yyyy/mm/dd')
;

Please advise how I create a query that I wont have to change each year and it will automatically fetch the current data from 9/1 to 8/31?

So here’s a question – if you want to write a piece of SQL that always gives the right answer whenever you run it, and doesn’t have to be modified each year, what’s the absolute minimum number of test scenarios that you should use to check that your code is correct ?

Update: My solution appears at comment #6 below.

January 6, 2010

Copy Stats

Filed under: Statistics — Jonathan Lewis @ 2:24 pm UTC Jan 6,2010

In a recent posting on OTN, someone was having trouble copying stats from one index to another using the import_index_stats and export_index_stats procedures from package dbms_stats modifying the contents of their “stat table” between the export and import.

(more…)

January 3, 2010

Pseudo-parallel

Filed under: Infrastructure,Parallel Execution — Jonathan Lewis @ 11:32 am UTC Jan 3,2010

There’s a posting on the OTN database forum asking for suggestions about restricting a query to data from one datafile of a tablespace.  It seems to be a slightly odd thing to do, but it reminded me of a “pseudo-parallel” trick I once used (and described) more than 10 years ago on a system running Oracle version 7. It was a long time ago, but I think I needed to do this because I wanted to execute a massive update with as many parallel threads as possible in the days when parallel DML wasn’t possible.

(more…)

January 1, 2010

First Principles

Filed under: humour — Jonathan Lewis @ 8:04 pm UTC Jan 1,2010

I just had to start the new year with a little humour.

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 819 other followers