Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

High cost full table scan when the expected cardinality is 1

User_OCZ1TMar 20 2017 — edited Apr 2 2017

hi  I am using version 11.2.0.4.0 of oracle. There is one query which is going for index scan and full table scan based on one constant value. when i use -999999 i.e. six 9's the query is going for full table scan, but in other combinations like five 9's and seven 9's its going for index range scan. also when i hint the index its cost going up.

There exist index on column ZE, when i use six 9's as filter criteria, its doesn't use index in a simple query though. Where as for other combinations(five 9's or seven 9's) its using index, i have published here the histogram details for that column. would you able to help me, what might be the cause behind this?  or its really a optimizer bug?

When i tried with -1*999999, it started using index. So i am bit confused here, my concern is , as i see very wired behaviour of optimizer so is it safe to compare here any other combination of 9's except six? or any other way we should handle?

I want to analyze this so that it wont affect some other queries in our database.

table stats:

---------------------

num_rows,avg_row_len,blocks

49157466    368    2453161

column_stats:

------------------

column_name,     data_tyPe,    num_distinct,density,            num_nulls, histogram

ZE                 NUMBER           48970450       7.46653127356624E-6    58718    HEIGHT BALANCED

indexes related to column:

------------------------

index_name         column_name column_Position

ZZI_IX2               ZE    1

select column_name, endpoint_number, endpoint_value from dba_tab_histograms where table_name='ZZE' and column_name='ZE'

column_name, endpoint_number, endpoint_value

ZE    0    -1

ZE    1    274478607

ZE    2    274877394

ZE    3    275127863

ZE    4    275469113

ZE    5    275760695

ZE    6    276057897

ZE    7    276387749

ZE    8    276671019

ZE    9    277003180

ZE    10    277331647

ZE    11    277587306

ZE    12    277952466

ZE    13    278266504

ZE    14    278526996

ZE    15    278889473

ZE    16    279158859

ZE    17    279481624

ZE    18    279827876

ZE    19    280122238

ZE    20    280425747

ZE    21    280748486

ZE    22    281031649

ZE    23    281395516

ZE    24    281719528

ZE    25    281991104

ZE    26    282315335

ZE    27    282663869

ZE    28    282941695

ZE    29    283288021

ZE    30    283586895

ZE    31    283889706

ZE    32    284210787

ZE    33    284559362

ZE    34    284874224

ZE    35    285199650

ZE    36    285525222

ZE    37    285781432

ZE    38    286128740

ZE    39    286356151

ZE    40    286707373

ZE    41    287003242

ZE    42    287320814

ZE    43    287641239

ZE    44    287897754

ZE    45    288217051

ZE    46    288507351

ZE    47    288809642

ZE    48    289116984

ZE    49    289388259

ZE    50    289724933

ZE    51    290008119

ZE    52    290323803

ZE    53    290635269

ZE    54    290902503

ZE    55    291257751

ZE    56    291568310

ZE    57    291867308

ZE    58    292172319

ZE    59    292421719

ZE    60    292745176

ZE    61    292997935

ZE    62    293324424

ZE    63    293646174

ZE    64    293912371

ZE    65    294271298

ZE    66    294541538

ZE    67    294848841

ZE    68    295116770

ZE    69    295443745

ZE    70    295802190

ZE    71    296157438

ZE    72    296413924

ZE    73    296768660

ZE    74    297028278

ZE    75    297368524

ZE    76    297690465

ZE    77    297947054

ZE    78    298339710

ZE    79    298609217

ZE    80    298958297

ZE    81    299299014

ZE    82    299556585

ZE    83    299909685

ZE    84    300213890

ZE    85    300578605

ZE    86    300905218

ZE    87    301194978

ZE    88    301538043

ZE    89    301842363

ZE    90    302159537

ZE    91    302515459

ZE    92    302783032

ZE    93    303177367

ZE    94    303524981

ZE    95    303790115

ZE    96    304152390

ZE    97    304460144

ZE    98    304776734

ZE    99    305179297

ZE    100    305436253

ZE    101    305818674

ZE    102    306165324

ZE    103    306452551

ZE    104    306788427

ZE    105    307093656

ZE    106    307457541

ZE    107    307804978

ZE    108    308128532

ZE    109    308477587

ZE    110    308825382

ZE    111    309107730

ZE    112    309475222

ZE    113    309804975

ZE    114    310165161

ZE    115    310471701

ZE    116    310784134

ZE    117    311126063

ZE    118    311396258

ZE    119    311739829

ZE    120    312098862

ZE    121    312410703

ZE    122    312752061

ZE    123    313017180

ZE    124    313323938

ZE    125    313627394

ZE    126    313979778

ZE    127    314244303

ZE    128    314580374

ZE    129    314879900

ZE    130    315212307

ZE    131    315465998

ZE    132    315754222

ZE    133    316045420

ZE    134    316358931

ZE    135    316618065

ZE    136    316917211

ZE    137    317201777

ZE    138    317532050

ZE    139    317789846

ZE    140    318062820

ZE    141    318360131

ZE    142    318628222

ZE    143    318926376

ZE    144    319243723

ZE    145    319501746

ZE    146    319848376

ZE    147    320118513

ZE    148    320442480

ZE    149    320699189

ZE    150    321034453

ZE    151    321295450

ZE    152    321617688

ZE    153    321886839

ZE    154    322217315

ZE    155    322508291

ZE    156    322844507

ZE    157    323102548

ZE    158    323439519

ZE    159    323701891

ZE    160    324036566

ZE    161    324304799

ZE    162    324655791

ZE    163    324885580

ZE    164    325294993

ZE    165    325530592

ZE    166    325898150

ZE    167    326168129

ZE    168    326507042

ZE    169    326782581

ZE    170    327124548

ZE    171    327364184

ZE    172    327768084

ZE    173    328062032

ZE    174    328402567

ZE    175    328683336

ZE    176    329034211

ZE    177    329270858

ZE    178    329645137

ZE    179    329894924

ZE    180    330243993

ZE    181    330545052

ZE    182    330885186

ZE    183    331151222

ZE    184    331493254

ZE    185    331770234

ZE    186    332052326

ZE    187    332351611

ZE    188    332624237

ZE    189    332963515

ZE    190    333199360

ZE    191    333614344

ZE    192    333889025

ZE    193    334230602

ZE    194    334517098

ZE    195    334867891

ZE    196    335109534

ZE    197    335459075

ZE    198    335724587

ZE    199    336071044

ZE    200    336382437

ZE    201    336670779

ZE    202    336984763

ZE    203    337334536

ZE    204    337607021

ZE    205    337953904

ZE    206    338220442

ZE    207    338561790

ZE    208    338856734

ZE    209    339149617

ZE    210    339447756

ZE    211    339737687

ZE    212    340072753

ZE    213    340359008

ZE    214    340628817

ZE    215    340952013

ZE    216    341246561

ZE    217    341483676

ZE    218    341914974

ZE    219    342148331

ZE    220    342428356

ZE    221    342723755

ZE    222    343006238

ZE    223    343346201

ZE    224    343577789

ZE    225    343935584

ZE    226    344175690

ZE    227    344467790

ZE    228    344805247

ZE    229    345109945

ZE    230    345444402

ZE    231    345647001

ZE    232    346044169

ZE    233    346282886

ZE    234    346567681

ZE    235    346901121

ZE    236    347101439

ZE    237    347458872

ZE    238    347726465

ZE    239    348039135

ZE    240    348333332

ZE    241    348556394

ZE    242    348901609

ZE    243    349163446

ZE    244    349408886

ZE    245    349730198

ZE    246    349960349

ZE    247    350286543

ZE    248    350552114

ZE    249    350818358

ZE    250    351145393

ZE    251    351376023

ZE    252    351645744

ZE    253    351943865

ZE    254    352144889

SQL> select  I.ZZIID from ZZI i where i.ZE=-99999; 

Elapsed: 00:00:00.00 

 

Execution Plan 

---------------------------------------------------------- 

Plan hash value: 1088234794 

 

---------------------------------------------------------------------------------------------------- 

| Id  | Operation                   | Name                 | Rows  | Bytes | Cost (%CPU)| Time     | 

---------------------------------------------------------------------------------------------------- 

|   0 | SELECT STATEMENT            |                      |     1 |    14 |     4   (0)| 00:00:01 | 

|   1 |  TABLE ACCESS BY INDEX ROWID| ZZI                  |     1 |    14 |     4   (0)| 00:00:01 | 

|*  2 |   INDEX RANGE SCAN          | ZZI_IX2              |     1 |       |     3   (0)| 00:00:01 | 

---------------------------------------------------------------------------------------------------- 

 

Predicate Information (identified by operation id): 

--------------------------------------------------- 

 

   2 - access("I"."ZE"=(-99999)) 

 

SQL> select  I.ZZIID from ZZI i where i.ZE=-9999999; 

Elapsed: 00:00:00.00 

 

Execution Plan 

---------------------------------------------------------- 

Plan hash value: 1088234794 

 

---------------------------------------------------------------------------------------------------- 

| Id  | Operation                   | Name                 | Rows  | Bytes | Cost (%CPU)| Time     | 

---------------------------------------------------------------------------------------------------- 

|   0 | SELECT STATEMENT            |                      |     1 |    14 |     4   (0)| 00:00:01 | 

|   1 |  TABLE ACCESS BY INDEX ROWID| ZZI                  |     1 |    14 |     4   (0)| 00:00:01 | 

|*  2 |   INDEX RANGE SCAN          | ZZI_IX2              |     1 |       |     3   (0)| 00:00:01 | 

---------------------------------------------------------------------------------------------------- 

 

Predicate Information (identified by operation id): 

--------------------------------------------------- 

 

   2 - access("I"."ZE"=(-9999999)) 

 

SQL> select  I.ZZIID from ZZI i where i.ZE=-999999; 

Elapsed: 00:00:00.00 

 

Execution Plan 

---------------------------------------------------------- 

Plan hash value: 2104890136 

 

---------------------------------------------------------------------------------------------- 

| Id  | Operation                 | Name             | Rows  | Bytes | Cost (%CPU)| Time     | 

---------------------------------------------------------------------------------------------- 

|   0 | SELECT STATEMENT          |                  |     1 |    20 | 54481   (6)| 00:04:37 | 

|*  1 |  TABLE ACCESS STORAGE FULL| ZZI              |     1 |    20 | 54481   (6)| 00:04:37 | 

---------------------------------------------------------------------------------------------- 

 

Predicate Information (identified by operation id): 

--------------------------------------------------- 

 

   1 - filter("I"."ZE"=(-999999)) 

     

     

SQL> select  I.ZZIID from ZZI i where i.ZE=-1*999999; 

Elapsed: 00:00:00.00 

 

Execution Plan 

---------------------------------------------------------- 

Plan hash value: 1088234794 

 

---------------------------------------------------------------------------------------------------- 

| Id  | Operation                   | Name                 | Rows  | Bytes | Cost (%CPU)| Time     | 

---------------------------------------------------------------------------------------------------- 

|   0 | SELECT STATEMENT            |                      |     1 |    14 |     4   (0)| 00:00:01 | 

|   1 |  TABLE ACCESS BY INDEX ROWID| ZZI                  |     1 |    14 |     4   (0)| 00:00:01 | 

|*  2 |   INDEX RANGE SCAN          | ZZI_IX2              |     1 |       |     3   (0)| 00:00:01 | 

---------------------------------------------------------------------------------------------------- 

 

Predicate Information (identified by operation id): 

--------------------------------------------------- 

 

   2 - access("I"."ZE"=(-999999))      

       1 - filter("I"."ZE"=(-999999)) 

      

------------- By forcing it to go for index with Six 9's------------------------

SQL> select /*+INDEX(I ZZI_IX2)*/ I.ZZIID from ZZI i where i.ZE=-999999;

Elapsed: 00:00:00.00

Execution Plan

----------------------------------------------------------

Plan hash value: 3306559304

----------------------------------------------------------------------------------------------------

| Id  | Operation                   | Name                 | Rows  | Bytes | Cost (%CPU)| Time     |

----------------------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT            |                      |     1 |    20 |   185K  (1)| 00:15:40 |

|   1 |  TABLE ACCESS BY INDEX ROWID| ZZI                  |     1 |    20 |   185K  (1)| 00:15:40 |

|*  2 |   INDEX FULL SCAN           | ZZI_IX2              |     1 |       |   185K  (1)| 00:15:40 |

----------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

   2 - filter("I"."ZE"=(-999999))      

This post has been answered by AndrewSayer on Apr 1 2017
Jump to Answer

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Apr 30 2017
Added on Mar 20 2017
8 comments
782 views