number of distinct values against a few distinct values

Hello
If I have a table with millions of records and I query this table with a where clause on a column with few unique values, it would execute faster than this column with many, many distinct values? If Yes, could someone please help me understand why? Where clause would simply like this:

where column1 = 'xyz '.

Could you please answer for cases where the column IS and is not indexed?

Thank you!

Hello

arizona9952 wrote:
Hello
If I have a table with millions of records and I query this table with a where clause on a column with few unique values, it would execute faster than this column with many, many distinct values?

It is the opposite; the query can be faster if you have more distinct values.

If Yes, could someone please help me understand why? Where clause would simply like this:

where column1 = 'xyz '.

Could you please answer for cases where the column IS and is not indexed?

Oracle will tend to use the indexes that are selective, meaning that there are many distinct values, and thus only a smaller percentage of the table than a given value.
Imagine you are in a library, and you are looking for an author of some books.
One way to do that is to look for the author of the catalogue, print a list of all books by this author and search for each of them. This is similar to using an index on a table.
Another way is to go through the rays, look at each book and see if there is the author of right. This corresponds to a full table scan.
If 5 authors wrote all the books in this librrary, while about 20% of the books in this library are by a given author, then the 2nd way might actually be faster; looking at each book can be faster than the search for many books, including, more you save the work of assistance from the catalog and store the results of catalog.

If the column is not indexed, it make much difference how many distinct values are in colum1.

Tags: Database

Similar Questions

  • Number of distinct users

    I have the following table

    UsersRegion
    [email protected]EMEA
    SSA. [email protected]APAC
    SSA. [email protected]APAC
    [email protected]EMEA
    [email protected]EMEA
    [email protected]DVL
    [email protected]DVL
    [email protected]EMEA
    [email protected]EMEA
    [email protected]EMEA

    I need to know the number of distinct users by region.

    If the result will give me EMEA - 5

    APAC - 1

    LAD - 1

    Can someone help me with the query?

    Hello

    You said.  A way of counting distinct users is COUNT (DISTINCT users):

    SELECT region

    COUNT (DISTINCT users)

    FROM table_x

    GROUP BY region;

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and INSERT only relevant columns statements) and the results desired from these data.
    Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places.
    If you change the query at all, post your modified version.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • Get the number of DISTINCT from several columns

    How can I get the number of DISTINCT from several columns?
    SQL> select count(distinct ename) from emp;
    
    COUNT(DISTINCTENAME)
    --------------------
                      14
    
    SQL> select count(distinct ename, job) from emp;
    select count(distinct ename, job) from emp
           *
    ERROR at line 1:
    ORA-00909: invalid number of arguments

    Hello

    select count(distinct ename || job) from emp;
    

    Kind regards

  • Number of distinct values need

    HI gurus of the oracle,.

    I have the table as

    NUMBER NAME
    11111one
    11111b
    222c
    222d
    555555e
    555555f
    555555g
    11h
    3333I have

    I need to select distinct (length (number)), count (number of records with the same length) of the table.

    output must be

    separate (length (Number)) count (occurrences)

    5                                      2

    3                                      2

    6                                      3

    2                                      1

    4                                      1

    Please help me in this regard.

    Thanks in advance.

    REDA

    so you were almost there...

    SELECT length (number), count (*)

    FROM THE DATA

    Length Group (number)

    /

    HTH

  • Number 2 distinct values

    Hello world

    I have a table like this format:

    PK | CompanyID | Plan

    1. 1. P
    2. 1. P
    3. 2. P
    4. 3. P
    5. 2. L
    6. 1. L


    and I want to count the number of output of P and L, like this:

    ID | P | L
    1. 2. 1
    2. 1. 1
    3. 1. 0

    Can someone point me in the right direction?

    Published by: Dan Surkan April 1, 2009 11:45
    SELECT   companyid, COUNT (CASE
                                  WHEN PLAN = 'P'
                                     THEN 1
                               END) cpt_p,
             COUNT (CASE
                       WHEN PLAN = 'L'
                          THEN 1
                    END) cpt_l
        FROM t
    GROUP BY companyid
    
    SQL> WITH t AS
      2       (SELECT 1 companyid, 'P' PLAN
      3          FROM DUAL
      4        UNION ALL
      5        SELECT 1, 'P' PLAN
      6          FROM DUAL
      7        UNION ALL
      8        SELECT 2, 'P' PLAN
      9          FROM DUAL
     10        UNION ALL
     11        SELECT 3, 'P' PLAN
     12          FROM DUAL
     13        UNION ALL
     14        SELECT 2, 'L' PLAN
     15          FROM DUAL
     16        UNION ALL
     17        SELECT 1, 'L' PLAN
     18          FROM DUAL)
     19  SELECT   companyid, COUNT (CASE
     20                                WHEN PLAN = 'P'
     21                                   THEN 1
     22                             END) cpt_p,
     23           COUNT (CASE
     24                     WHEN PLAN = 'L'
     25                        THEN 1
     26                  END) cpt_l
     27      FROM t
     28  GROUP BY companyid;
    
     COMPANYID      CPT_P      CPT_L
    ---------- ---------- ----------
             1          2          1
             2          1          1
             3          1          0
    
    SQL> 
    

    Published by: Salim champion 2009-04-01 10:51

  • Get-vmhost does not reflect the number of correct hosts on a few scenarios

    Hello members of the community.

    When I try to use the cmdlet get-vmhost against a cluster that has one or no hosts in there, I don't get the number of correct hosts. Here are some lines for this information.

    foreach ($objDataCenter to $objColDataCenters)
    {
    $objColClusters = get-Cluster-location $objDataCenter

    foreach ($objcluster to $objColClusters)
    {
    $Details = $Null
    $objClusterBaseRP = $objHosts = $objDataStores = $objVMs = $Null
    $intNUmDatastores = $intNumHostCPUs = $intTotCPUMhz = $intTotUsageCPUMhz = 0
    $intTotMemMB = $intTotUsageMemMB = 0
    $CPUStat = $CPUStatMax = $MemoryStat = $MemoryStatMax = 0
    $intTotMemGB = $intUsageGB = $intMemResGB = $intMemLmtGB = 0
    $inttOTDiskCapacityMB = $intTotDiskFreeMB = $intTotDSCapacityGB = $intTotDSFreeGB = 0
    $intTotVMMemGB = $intTotVMCPUMhz = $intNumVMCpus = $intTotVMMemMB = 0
    $intTotVMProvisionedSpaceGB = $intTotVMUsedSpaceGB = 0

    $objHosts = get-vmHost-location $objcluster

    $objHosts.Count

    }

    }

    code above produce white for clusters that has one host for all other groupings that has 2 or several hosts results are correct. I know that there is no point of having a single node cluster or not, but the result does not reflect his decent stats.

    In the same way under lines also produce incorrect information to the cluster that has no HOST or a single HOST that is in maintenance mode and has no inside VMs

    $objVMs = get-VM-location $objCluster

    $objVMs | %{
    $intNumVMCpus += $_. NumCpu
    $intTotVMMemMB += $_. MemoryMB
    $intTotVMProvisionedSpaceGB += $_. ProvisionedSpaceGB
    $intTotVMUsedSpaceGB += $_.usedSpaceGB

    }

    When I print the values of all the variables above, it should report 0 instead I have the chance to see some numbers. Please note I have explicitly assign values $null to all objects and 0 in all other variables at the beginning of the loop for clusters.

    Any help to solve this is greatly appreciated - thanks

    Kind regards, Philippe

    Hello, Ramkrish-

    Welcome to the communities.

    For the first part, the number of hosts in a cluster with zero (0) or one 1 host - there are a number of things happening there.

    When the Get-VMHost call returns only one host, and you then try to access to the. Property of the count of $objHosts, you try to access this property on an object VMHost, not an array of length 1 with a VMHost inside.  And, since the VMHost object has no property '. " Count' you get a return of the 'white' or null.

    And when Get-VMHost will return no host, and you are trying to access. Count on $objHosts, you effectively type '$null. "Count", since $objHosts - eq $null at that time.

    Two ways to handle these cases would be to use the Measure-Object cmdlet or explicitly to a table, even if zero or one VMHosts are returned.  As:

    ## using Measure-Object$objHosts = Get-VMHost -Location $objcluster($objHosts | Measure-Object).Count    ## correctly returns 0 or 1 (or greater)...## or## forcing an array, even if 0 or 1 items returned$objHosts = @(Get-VMHost -Location $objcluster)$objHosts.Count        ## correctly returns 0 or 1 (or greater)...
    

    Regarding the behavior you're seeing with the statement Foreach-Object with $objVMs, I suspect that the behavior of the Foreach-Object statement when you're running an empyt null him is at stake here.  In other words, while you can imagine "$arrEmptyArray | % {'Hello'}' to produce anything, happening actually by an interation of the loop (really - try - the).  So to avoid this, you can delete the unnecessary part that stores the output of Get - VM in the variable "$objVMs" and combine the lines to channel the output from Get - VM directly to the Foreach-Object statement, as:

    Get-VM -Location $objCluster | %{    $intNumVMCpus += $_.NumCpu    $intTotVMMemMB += $_.MemoryMB    $intTotVMProvisionedSpaceGB += $_.ProvisionedSpaceGB    $intTotVMUsedSpaceGB += $_.usedSpaceGB}
    

    By the way: while we're updating this code a little, another way that you could get these totals is again using the Measure-Object cmdlet, this time with the parameter - sum, as:

    Get-VM -Location $objCluster | Measure-Object -Sum -Property NumCpu, MemoryMB, ProvisionedSpaceGB, usedSpaceGB
    

    Much more compact and allows just of PowerShell do the work.  Although you then maintain the return of the object of measures, depending on the situation, it is quite practical.

    How about that?

  • chain number by "scan value" format string "%.3f" doesn'work

    I had a little problem.

    "To convert a string to a number, I use the function"scan value"with '%.3f' for the ' format string"connector. I would get a 3 digit number. But this doesn't work with the parameter "%.3f.

    Thank you.

    Please check the syntax of using LV Format specifier. There is a table that describes the purpose of each specifier. When you read in the description "when you use a function in shape", the specifier is applied to the number-> string, when you read "when you use a sweep feature", the specifier applies to the String-> number. The syntax of width element applies to both situations, the. Element of syntax accuracy does not work.

  • convert oracle.jbo.domain.number of positive value to a negative value in EL Expression

    Hi all

    jdev: 11.1.1.4

    My use case is to try to convert positive user input negative number, once the user presses the tab key

    I use the Employee in the HR schema table and when any kind of user + ve value in the salary column, then be converted into value - EV.

    < af:inputText value = "#{bindings." Salary.inputValue.value > 0? 0 - links. Salary.inputValue.value: links. Salary.inputValue}.

    label = "#{bindings." Salary.hints.label}.

    autoSubmit = "true" >

    < af:convertNumber type = "currency".

    currencySymbol = "$" integerOnly = "true".

    minFractionDigits = '0' maxFractionDigits = "0".

    groupingUsed = 'false' local = "en-US" / >

    < / af:inputText >

    It's work the converted number in ve - but it makes the readonly entry text box. If the user was not able to change the value.

    Kind regards

    Krishan

    I don't think it can be done in EL only. the problem is that you change the location of storage. I suggest that you use a value valueChangeListener and climatiqueLes in there as

    {} public void numberChangeListener (ValueChangeEvent valueChangeEvent)

    Integer i = valueChangeEvent.getNewValue ((Integer));

    If (i > 0) {}

    get the link container

    BindingContainer links is BindingContext.getCurrent () .getCurrentBindingsEntry ();.

    updates to process

    FacesContext will involve = FacesContext.getCurrentInstance ();

    valueChangeEvent.getComponent () .processUpdates (contxt);

    get a definitions page ADF ADF attributevalue

    AttributeBinding attr = (AttributeBinding) bindings.getControlBinding ("Salary").

    attr.setInputValue(i*-1);

    PPR refresh a component jsf

    AdfFacesContext.getCurrentInstance () .addPartialTarget (valueChangeEvent.getComponent ());

    }

    Timo

  • Carve out a number in char value

    Hello

    I have a number of 0,0027 and need to convert the value of character 0,0027, I tried to use under query, but the value est.0027 with no previous 0 to the decimal

    Select substr (to_char (0.0027), 1, 6) of double

    How can I get the result 0,0027.

    Thank you

    Try below

    SQL > select to_char ('0.0027 ','990.9999 ') of double

    2.

    TO_CHAR ('0.0027 ','990.9999 ')

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

    0,0027

    SQL >

  • 10g BEEP format-number for negative values does not

    Hi all

    I tried the following methods to get the negative number locked up with symbols ().

    1 update the mask of BI Publisher properties of field format to

    "#, # 0.00;(#,##0.00).

    2 tried the Oracle formatting options

    <? format - number:A.INVOICE_AMOUNT; "PT999G999G999G999G999G999G999D00? >

    What gives me the result as below,

    Output value

    23.45 23.45 - print correctly

    -12.90 (12.90 - closing paren "")' does not print

    Please help me get the parenthesis when generating the PDF file.

    Thank you

    I had the question.

    This is the format that was used in your model

    ###,###,###,###,###,###,###,##0.00;(#)

    The first half before; does the mask so no problem.

    But after; which is for negative values and that is not the correct format.

    Please use this format on the properties of form field that gives you good number format

    #, ##0.00;(#,##0.00)

  • Number in event.value script format

    I have a script that retrieves data from a numeric field (r18) then add a space and the text "annual vacation Credits."  Currently, the result is something like "100000 credits of annual vacation.

    I am trying to format the number to include if necessary comma (ex: 10,000 or 100 000 or 1 000 000 etc.).

    Here is the current script:

    Get the field values as strings

    var = getField R18

    .valueAsString ("r18");

    Combine values

    Event.Value = r18 + 'annual vacation Credits ".

    Any help is appreciated

    It is possible to format numbers and dates using the util object in Acrobat JavaScript.

    Get the value of the field;
    R18 var is getField ("r18") .value;.
    formatting the value and concatenate text
    Event.Value = util.printf ("%, 0 1.2F", r18) + 'vacation Credits. "

    or

    Get the value of the field;
    R18 var is getField ("r18") .value;.
    format, including the text value;
    Event.Value = util.printf ("%, 0 1.2F annual vacation credits", r18);

  • Conversion input of characters in number or money value

    Hello everyone. I have an element, overtime pay.

    It has entries:

    proportion
    hourly amount
    number of hours

    the formula is proportion * hourly amount * number of hours

    Now, I want to restrict the input value in proportion to only two values 1 and 1.2
    to do this, I created a set of values and attached to the input value
    I had to change the data type of the input in proportion to the character value because the number data type does not support the values/research
    the problem comes from the formula

    I'm going home
    overtime = to_number (proportion) * hourly amount * number of hours

    but I get an error

    using
    overtime = proportion * hourly amount * number of hours

    an error as well
    Does anyone know how to fix it?
    Thank you very much

    Hi innocent,

    Try to do the conversion first and his assignment to a local variable before doing the calculation.

    Example of
    l_num_proportion = 0

    l_num_proportion = to_number (proportion)

    overtime = l_num_proportion * hourly amount * number of hours

    It will be useful.

    Thank you
    Sanjay

  • Number of unique values in 7 columns

    Hey there...
    I have a table of correspondence with 8 columns
    ID = unique ID
    U = Sunday,
    M = Monday
    T = TUE
    W = married
    R = Thur
    F = Fri
    S = Sat

    Each of the columns 'day' can be a value between 1 and 1150, looks like this

    ID U M T W R F S
    1 15 15 16 15 17 345 17

    What I'm trying to find is a county of the deviation of each line... or how many days have different values

    So for the example above

    ID U M T W R F S COUNTY
    1 15 15 16 15 17 345 17 4

    There are have 4 unique values in the week...
    15,16,17,345

    Any ideas on how this could be done in oracle? Puzzled!
    SQL> create or replace
      2    type NumberList
      3      as
      4         table of number
      5  /
    
    Type created.
    
    SQL> with sample_table as(
      2                       select 1 ID,15 U,15 M,16 T,15 W,17 R,345 F,17 S from dual
      3                      )
      4  select  s.*,
      5          cardinality(set(NumberList(U,M,T,W,R,F,S))) cnt
      6    from  sample_table s
      7  /
    
            ID          U          M          T          W          R          F          S        CNT
    ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
             1         15         15         16         15         17        345         17          4
    
    SQL> 
    

    SY.

  • Increase the number of lookup values display only once the research of windo

    Hi all

    Must I increase the number of display of the values of result on a search (search for say, organization) window on the administration and the user console.
    Currently, it is 10.

    How can I do this?

    Kind regards
    Chaturanga

    Modify the JSP

  • Convert a decimal number to time value...

    Hi guys,.

    I convert a time value represented by decimal format hh:ss. I came up with the following... Is there an easy way (elegant) to do?

    SUBSTR (TO_CHAR (time), 0, (INSTR (TO_CHAR (time),'. ') select-1)). ':' ||

    To_char ((TO_NUMBER (substr (to_char (Time), (INSTR (TO_CHAR (time),'. ') + 1), LENGTH (time))) / 100) * 60)

    from (select ' 6533.50' double time ');

    Thank you

    Napster

    SELECT TRUNC (T) |': ' | (T TRUNC (T)) * 60

    Of

    (select ' 6533.50' double T ');

    6533:30

    ----

    Ramin Hashimzade

Maybe you are looking for

  • IOS 10 update not recognized

    My IPad does not recognize the update IOS 10.  After clicking on settings > general > software update, it says "IOS 9.3.5 your software is up-to-date."  How can I get this iPad to access and download IOS 10?

  • Deletion/blocking App

    I'm trying to block an application which was purchased to be reinstalled on the device. The app has been removed from the aircraft, but they still have the ability to re - install the app without give their permission. Is there a way to block the app

  • Mailing address: is it possible to avoid downloading spam?

    I get a lot of junk emails on my two iCloud and Gmail accounts, that I am connected to the messaging application. What I would like to prevent Mail to download any email marked as spam at once iCloud and Gmail servers: I'm happy with both their unwan

  • Satellite L650-12 q keeps freezing whenever I have start the video or the phone call

    Hello I recently bought a portable Satellite L650-12 q who played perfectly until I tried a video MSN Chat (MSN messenger and Skype). Within seconds of starting the conversation, the computer crashes completely. I get a static screen and nothing work

  • Can I format a sata HD of the router WRT1900AC e?

    I have a HD plugged into my router WRT1900AC though the eSata port.  Currently, the HD does not have the correct format and should be reformatted. Can I make my PC through the router?