Re: Optimizer estimated cardinality very low

From: Daniel Coello <coello.daniel_at_gmail.com>
Date: Mon, 26 Oct 2020 13:06:46 -0400
Message-ID: <CADX5pQXcgEKn7jqTy2VfvhKGm2puwnMA-zDYFk=DTKOUCf0vkg_at_mail.gmail.com>



Hi Nenand.

For when the interval when the estimation is good: ...
Join ColGroups for ORDER_REQST[ORDER_REQST] and ORDER_DETL[ORDER_DETL] : Using cdn sanity check
...

Below is some information relevant to the columns: ORDER_REQST
  PARTITION_NAME COLUMN_NAME NUM_DISTINCT NUM_BUCKETS SAMPLE_SIZE HISTOGRAM NUM_ROW
IN PARTITION
JULY SYS_P971481 ORDR_RQST_DATE 3 3 26895392 FREQUENCY 26895392 SYS_P971481 SYS_STU4S$4GK1UDMC2M8$MI#W6QS_ 26636288 1 26895392 NONE 26895392 SYS_P971481 ORDR_RQST_NUMBER 26895392 1 26895392 NONE 26895392 JUNE SYS_P964661 ORDR_RQST_DATE 4 4 17506471 FREQUENCY 17506471 SYS_P964661 SYS_STU4S$4GK1UDMC2M8$MI#W6QS_ 15794176 1 17506471 NONE 17506471 SYS_P964661 ORDR_RQST_NUMBER 15649792 1 17506471 NONE 17506471 ORDER_DETL   PARTITION_NAME COLUMN_NAME NUM_DISTINCT NUM_BUCKETS SAMPLE_SIZE HISTOGRAM NUM_ROW
IN PARTITION
JULY SYS_P971761 ORDR_RQST_DATE 3 3 32314200 FREQUENCY 32314200 SYS_P971761 SYS_STU4S$4GK1UDMC2M8$MI#W6QS_ 26636288 1 32314200 NONE 32314200 SYS_P971761 ORDR_RQST_NUMBER 26984448 1 32314200 NONE 32314200 JUNE SYS_P964866 ORDR_RQST_DATE 4 4 21814573 FREQUENCY 21814573 SYS_P964866 SYS_STU4S$4GK1UDMC2M8$MI#W6QS_ 15794176 1 21814573 NONE 21814573 SYS_P964866 ORDR_RQST_NUMBER 15649792 1 21814573 NONE 21814573 Things that have been pointed out to me or relevant to the env: - NUM_DISTINCT for the column_group in July are lower than ORDR_RQST_NUMBER instead of being equal or higher. This happens across other partitions but the estimation doesn't seem impacted by this alone. - I added the NUM_ROW values from the partitions for comparison with the total number of rows in it.
- ORDER_DETL columns' values should exist in ORDER_REQST, there shouldn't be an orphan row which in real counts you can see.

  • The actual count for distincts are: *July:* ORDER_REQST ORDR_RQST_NUMBER: 26846523 COL_GROUP ( ORDR_RQST_NUMBER , ORDR_RQST_DATE ): 26846523
ORDER_DETL
ORDR_RQST_NUMBER: 26846523
COL_GROUP ( ORDR_RQST_NUMBER , ORDR_RQST_DATE ) : 26846523 *June:*
ORDER_REQST
ORDR_RQST_NUMBER : 15683040
COL_GROUP ( ORDR_RQST_NUMBER , ORDR_RQST_DATE ) : 15683040 ORDER_DETL
ORDR_RQST_NUMBER : 15683040
COL_GROUP ( ORDR_RQST_NUMBER , ORDR_RQST_DATE ) : 15683040 Thanks,

On Mon, Oct 26, 2020 at 11:52 AM Noveljic Nenad <nenad.noveljic_at_vontobel.com> wrote:

> Hi Daniel,
>
>
>
> The regular semi-join cardinality calculation
>
>
>
> card = Card(outer) / (greater(NDV(mainq),NDV(subq))
>
>
>
> definitely underestimates correlated tables. Simply put, it can’t produce
> a good estimate for your case.
>
>
>
> The fallback formula with disabled extended statistics is also not good
> for the correlated tables:
>
>
>
> Card = card(mainq) * card(subq) / NDV(mainq) / NDV(subq)
>
>
>
> We still don’t know the condition that triggered “Using cdn sanity check
> “ in the good run.
>
>
>
> Could you also extract the entry “Join ColGroups for” from the CBO trace
> of the good run?
>
>
>
> Best regards,
>
>
>
> Nenad
>
>
>
> https://nenadnoveljic.com/blog
>
>
>
>
>
>
>
> *From:* Noveljic Nenad
> *Sent:* Montag, 26. Oktober 2020 15:24
> *To:* 'Daniel Coello' <coello.daniel_at_gmail.com>; ORACLE-L (
> oracle-l_at_freelists.org) <oracle-l_at_freelists.org>
> *Subject:* RE: Optimizer estimated cardinality very low
>
>
>
> Hi Daniel,
>
>
>
> A high NDV(ORDR_RQST_NUMBER,ORDR_RQST_DATE) of ORDER_DETL must be one of
> the factors contributing to cardinality 1.
>
>
>
> To figure out the difference in behavior between the July and June
> partition it would be helpful to see the num_distinct from
> DBA_PART_COL_STATISTICS. (You originally probably provided the statistics
> from dba_tab_cols, but the optimizer uses the partition column statistics
> for the NDV calculation.)
>
>
>
> "Would there be a way to force the sanity checks to kick in?"
>
>
>
> I couldn't find an undocumented parameter. But when I manipulated
> num_distinct of the extended statistic by just ~1%, the sanity check
> started kicking in. Taking a look at DBA_PART_COL_STATISTICS might help
> answering this question.
>
>
>
> Best regards,
>
>
>
> Nenad
>
>
>
> https://nenadnoveljic.com/blog
>
>
>
> ____________________________________________________
>
> Please consider the environment before printing this e-mail.
>
> Bitte denken Sie an die Umwelt, bevor Sie dieses E-Mail drucken.
>
>
> Important Notice
> This message is intended only for the individual named. It may contain
> confidential or privileged information. If you are not the named addressee
> you should in particular not disseminate, distribute, modify or copy this
> e-mail. Please notify the sender immediately by e-mail, if you have
> received this message by mistake and delete it from your system.
> Without prejudice to any contractual agreements between you and us which
> shall prevail in any case, we take it as your authorization to correspond
> with you by e-mail if you send us messages by e-mail. However, we reserve
> the right not to execute orders and instructions transmitted by e-mail at
> any time and without further explanation.
> E-mail transmission may not be secure or error-free as information could
> be intercepted, corrupted, lost, destroyed, arrive late or incomplete. Also
> processing of incoming e-mails cannot be guaranteed. All liability of
> Vontobel Holding Ltd. and any of its affiliates (hereinafter collectively
> referred to as "Vontobel Group") for any damages resulting from e-mail use
> is excluded. You are advised that urgent and time sensitive messages should
> not be sent by e-mail and if verification is required please request a
> printed version. Please note that all e-mail communications to and from the
> Vontobel Group are subject to electronic storage and review by Vontobel
> Group. Unless stated to the contrary and without prejudice to any
> contractual agreements between you and Vontobel Group which shall prevail
> in any case, e-mail-communication is for informational purposes only and is
> not intended as an offer or solicitation for the purchase or sale of any
> financial instrument or as an official confirmation of any transaction.
> The legal basis for the processing of your personal data is the legitimate
> interest to develop a commercial relationship with you, as well as your
> consent to forward you commercial communications. You can exercise, at any
> time and under the terms established under current regulation, your rights.
> If you prefer not to receive any further communications, please contact
> your client relationship manager if you are a client of Vontobel Group or
> notify the sender. Please note for an exact reference to the affected group
> entity the corporate e-mail signature. For further information about data
> privacy at Vontobel Group please consult www.vontobel.com.
>

-- 
Daniel Coello Villacis

--
http://www.freelists.org/webpage/oracle-l
Received on Mon Oct 26 2020 - 18:06:46 CET

Original text of this message