Cover | Table of Contents | Colophon
SELECT statements, that
is). Even for the rest, the problem usually lies in a subquery nested
inside the problem update or insert.
Last_Name in a Persons table allows rapid access to the
list of table rows where Last_Name='SMITH' or where Last_Name>='X' AND Last_Name<'Y'.
Unlike indexes in a book, however, database indexes are almost
effortless to use; the database is responsible for walking through the
indexes it chooses to use, to find the rows a query requires, and it
usually finds the right indexes to use without being told. Databases
don't always make the right choice, however, and the material in this
book exists largely to address such problems.11' falls between '1' and '2'. Indexes often cover multiple columns,
but you can think of such indexes as having a single sort key made up
of the concatenation of the multiple column values, with suitable
padding to cause sorting on the second column to begin only after
completing the sort on the first column.
SELECT ... FROM Orders, Order_Details;
WHERE clause at all,
the database has no instructions on how to combine rows from these two
large tables, and it does the logically simplest thing: it returns
every possible combination of rows from the tables. If you had
1,000,000 orders and 5,000,000 order details, you would get (if you
could wait long enough) 5,000,000,000,000 rows back from the query!
This is the rarely used and even more rarely useful Cartesian join. The result, every
combination of elements from two or more sets, is known as the
Cartesian product. From a business perspective,
you would have no interest in combining data from orders and order
details that had no relationship to each other. When you find
Cartesian joins, they are almost always a mistake.PLAN_TABLE. If you
do not already have a PLAN_TABLE in
the schema you are using to investigate execution plans, create one.
You can create an up-to-date PLAN_TABLE with the utlxplan.sql script in the rdbms/admin directory under ORACLE_HOME. If you cannot reach ORACLE_HOME, you can create a serviceable
PLAN_TABLE with this script:CREATE TABLE PLAN_TABLE( STATEMENT_ID VARCHAR2(30), TIMESTAMP DATE, REMARKS VARCHAR2(80), OPERATION VARCHAR2(30), OPTIONS VARCHAR2(30), OBJECT_NODE VARCHAR2(128), OBJECT_OWNER VARCHAR2(30), OBJECT_NAME VARCHAR2(30), OBJECT_INSTANCE NUMBER(38), OBJECT_TYPE VARCHAR2(30), OPTIMIZER VARCHAR2(255), SEARCH_COLUMNS NUMBER(38), ID NUMBER(38), PARENT_ID NUMBER(38), POSITION NUMBER(38), COST NUMBER(38), CARDINALITY NUMBER(38), BYTES NUMBER(38), OTHER_TAG VARCHAR2(255), OTHER LONG);
EXPLAIN_INSTANCE
EXPLAIN_STREAMEXPLAIN_OBJECTEXPLAIN_ARGUMENTEXPLAIN_OPERATOREXPLAIN_PREDICATEEXPLAIN_STATEMENTSomeAlias.Leading_Indexed_Column=<Expression>BETWEEN, LIKE, <, >, <=, or >=. These range comparisons also
potentially enable use of the index, but the index range is likely to
be larger and the resulting query therefore slower. If the index range
is too large, the optimizer might conclude that the index is not worth
using and choose another path to the data. When you combine equalities
and range conditions for multicolumn indexes, you should prefer
indexes that lead with the columns that have equality conditions and
finish with columns that have range conditions. Note that the left
side of the comparison simply names the column, with no function
around the column, and no expression (such as addition) using the
column. Use of a function, a type conversion, or an arithmetic expression
on the side with the indexed column will generally disable use of that
index.-- File called runstats_schema.sql SELECT 'RUNSTATS ON TABLE<Schema_Name>.' || TABNAME || ' AND INDEXES ALL;' FROM SYSCAT.TABLES WHERE TABSCHEMA = '<Schema_Name>';
quit;, and run the following two
commands from the Unix shell:db2 +p -t < runstats_schema.sql > tmp_runstats.sql grep RUNSTATS tmp_runstats.sql | db2 +p -t > tmp_anal.out
FORCEPLAN when necessary.UPDATE STATISTICS commands into the
query window and run them as well:-- file called updateall.sql -- update your whole database SELECT 'UPDATE STATISTICS ', name FROM sysobjects WHERE type = 'U'
Eflag on the
nonindexed column Exempt_Flag of
the Employees table, run:CREATE STATISTICS EFlag on Employees(Exempt_Flag)
While camping, Johnny cooked eight flapjacks, three sausages, one strip of bacon, and two eggs for himself and each of his friends, Jim, Mary, and Sue. The girls each gave one-third of their sausages, 25% of their flapjacks, and half their eggs to the boys. Jim dropped a flapjack and two sausages, and they were stolen by a raccoon. Johnny is allergic to maple syrup, and Mary had strawberries on half her flapjacks, but otherwise everyone used maple syrup on their flapjacks. How many flapjacks did the kids eat with maple syrup?