Oracle – Cost and Cards

PC & Tech Category


Oracle DBA - Cost and CardsLast month I have received one question.In the explain plan the COST & CARDS is based on what? In this article we will see what it means and its usage.

First of all we see about the Cost.

COST

Cost of the operation as estimated by the optimizer’s cost-based approach.

The value of this column does not have any particular unit of measurement; it is merely a weighted value used to compare costs of execution plans. The value of this column is a function of the CPU_COST and IO_COST columns.

For statements that use the rule-based approach, this column is null. Cost is not determined for table access operations.

CPU_COST

CPU costs depend upon system load – The CPU costs associated with servicing an Oracle query depend upon the server load, and CPU costs are generally not important unless the entire Oracle instance is using excessive CPU resources.

IO_COST

Oracle estimates the I/O cost of the SQL based upon its knowledge of the settings for db_file_multiblock_read_count, the tablespace block size and the presence of indexes. Oracle does NOT use data buffer statistics because Oracle cannot have an a-priori knowledge of whether a desired data block is already cached in the RAM data buffers.

Next one is CARDS

Estimate by the cost-based approach of the number of rows accessed by the operation.

Example:

1. Execution plan

SQL> select * from dba_objects

2 where status=’INVALID’

3 order by object_name;

———————————————————-
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=75 Card=263 Bytes=46551)
1 0 SORT (ORDER BY) (Cost=75 Card=263 Bytes=46551)
2 1 VIEW OF ‘DBA_OBJECTS’ (VIEW) (Cost=74 Card=263 Bytes=46551)
3 2 UNION-ALL
4 3 FILTER
5 4 HASH JOIN (Cost=74 Card=281 Bytes=25852)
6 5 TABLE ACCESS (FULL) OF ‘USER Card=336 Bytes=5376)
7 5 TABLE ACCESS (FULL) OF ‘OBJ ard=281 Bytes=21356)
8 4 TABLE ACCESS (BY INDEX ROWID) OF ‘IND (Cost=2 Card=1 Bytes=8)
9 8 INDEX (UNIQUE SCAN) OF ‘I_IND1’ (INDEX (UNIQUE)) (Cost=1 Card=1)
10 3 FILTER
11 10 HASH JOIN (Cost=8 Card=27 Bytes=945)
12 11 TABLE ACCESS (FULL) OF ‘LINK ard=27 Bytes=513)
13 11 TABLE ACCESS (FULL) OF ‘USER Card=336 Bytes=5376)

Here CARD means number of rows accessed by this query.

Bytes –> No of bytes records fetched by query

Here Cost=75 Card=263 Bytes=46551

2. Explain plan

SQL> Explain plan for select * from dba_objects
2 where status=’INVALID’
3 order by object_name;

Explained.

SQL> select * from table(dbms_xplan.display);

PLAN_TABLE_OUTPUT
————————————————————————————————–
Plan hash value: 125482147

———————————————————————————————
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
———————————————————————————————–
| 0 | SELECT STATEMENT | | 263 | 46551 | 75 (4)| 00:00:02 |
| 1 | SORT ORDER BY | | 263 | 46551 | 75 (4)| 00:00:02 |
| 2 | VIEW | DBA_OBJECTS | 263 | 46551 | 74 (3)| 00:00:02 |
| 3 | UNION-ALL | | | | | |
|* 4 | FILTER | | | | | |
|* 5 | HASH JOIN | | 281 | 25852 | 74 (3)| 00:00:02 |
| 6 | TABLE ACCESS FULL | USER$ | 336 | 5376 | 5 (0)| 00:00:01 |
|* 7 | TABLE ACCESS FULL | OBJ$ | 281 | 21356 | 69 (3)| 00:00:01 |
|* 8 | TABLE ACCESS BY INDEX ROWID| IND$ | 1 | 8 | 2 (0)| 00:00:01 |
|* 9 | INDEX UNIQUE SCAN | I_IND1 | 1 | | 1 (0)| 00:00:01 |
|* 10 | FILTER | | | | | |
|* 11 | HASH JOIN | | 27 | 945 | 8 (13)| 00:00:01 |
| 12 | TABLE ACCESS FULL | LINK$ | 27 | 513 | 2 (0)| 00:00:01 |
| 13 | TABLE ACCESS FULL | USER$ | 336 | 5376 | 5 (0)| 00:00:01 |
———————————————————————————————–

I Hope this article helped you to understand about cost and cards.Suggestions are welcome.

Tags:

Edward Ramamoorthy Avatar

Help Us Grow

If you like this post, please share it with your friends.

You are free to copy and redistribute this article in any medium or format, as long as you keep the links in the article or provide a link back to this page.

Subscribe to Newsletter




Privacy Settings

Privacy & Cookie Overview

Our website uses cookies to provide you with the best user experience possible. These cookies are stored in your browser and perform essential functions such as recognizing you when you return to our website, as well as helping us to understand which sections of the website you find most useful and engaging.

To learn more, you can read our Privacy & Cookie Policy or reach out through our Contact form.

Strictly Necessary Cookies

Strictly Necessary Cookies must always be enabled to ensure the proper functioning of this website and to allow us to provide you with excellent service. These cookies are also essential for saving your cookie preferences.

Google Adsense

We use Google AdSense to keep this site free by displaying relevant ads. AdSense requires essential cookies that cannot be disabled, but you can manage other cookies. We respect your privacy and provide options to control non-essential cookies.

For more details on how Google handles your data, visit Google's Data Usage Policy. Please review our Privacy Policy for more information on how we protect your data.

AddToAny

We use AddToAny for social sharing. It doesn’t store cookies, ensuring a privacy-friendly experience. AddToAny complies with GDPR and CCPA by default.

For more, see their Privacy Policy.

OneSignal

We use OneSignal to send notifications to users who opt in. OneSignal complies with GDPR and is certified under the EU-US and Swiss-US Privacy Shield frameworks.

For more, see their Privacy Policy.

3rd Party Cookies

This website utilizes third-party cookies, which can enhance your experience and support our ongoing efforts to improve our services.

Google Analytics

We use Google Analytics to collect anonymous data, such as visitor numbers and popular pages, to improve user experience and site performance. Keeping this cookie enabled helps us refine the site based on visitor activity.

For more information, see Google’s Privacy Policy.

Discover more from Prime Inspiration

Subscribe now to keep reading and get access to the full archive.

Continue reading