Does the order of columns in an index matter?

Hi,
I have a table having composite index, five columns. (col1,col2,col3,col4,col5)
Currently , my index is beginning with the column which having low distinct values and so on.
( in my case the first column have 1 distinct values due to functional behavior ). the second column have 3 distinct values , the third column have many distinct value ( half of the table).
There are many DML queries on this table with different clauses.
Examples:
query 1 : where col1 =val1 and col2 = val2
query 2 : where (col3,col4) in ( select col1,col2 from another_table ) ( for this we can add col1 =val1 and col2 = val2)
My question is : what this best way to create index on this case ?
The order of columns on index depends on its distinct values?
Thanks

BIJGA wrote:
Hi,
I have a table having composite index, five columns. (col1,col2,col3,col4,col5)
Currently , my index is beginning with the column which having low distinct values and so on.
( in my case the first column have 1 distinct values due to functional behavior ). the second column have 3 distinct values , the third column have many distinct value ( half of the table).
There are many DML queries on this table with different clauses.
Examples:
query 1 : where col1 =val1 and col2 = val2
query 2 : where (col3,col4) in ( select col1,col2 from another_table ) ( for this we can add col1 =val1 and col2 = val2)
My question is : what this best way to create index on this case ?CREATE INDEX
The order of columns on index depends on its distinct values? yes
Handle:     BIJGA
Status Level:     Newbie (5)
Registered:     Aug 24, 2009
Total Posts:     66
Total Questions:     18 (14 unresolved)
I extend my condolences to you since you rarely get answers to your questions.

Similar Messages

  • Is there any performance difference in the order of columns referencing index?

    I wish to find out if there is any performance difference or efficiency in specifying those columns referencing index(es) first in the WHERE clause of SQL statements. That is, whether the order of columns referencing the index is important???.
    E.g. id is the column that is indexed
    SELECT * FROM a where a.id='1' and a.name='John';
    SELECT * FROM a where a.name='John' and a.id='1';
    Is there any differences in terms of efficiency of the 2 statements??
    Please advise. Thanks.

    There is no difference between the two statements under either the RBO or the CBO.
    sql>create table a as select * from all_objects;
    Table created.
    sql>create index a_index on a(object_id);
    Index created.
    sql>analyze table a compute statistics;
    Table analyzed.
    sql>select count(*)
      2    from a
      3   where object_id = 1
      4     and object_name = 'x';
    COUNT(*)
            0
    1 row selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1 Bytes=29)
       1    0   SORT (AGGREGATE)
       2    1     TABLE ACCESS (BY INDEX ROWID) OF 'A' (Cost=1 Card=1 Bytes=29)
       3    2       INDEX (RANGE SCAN) OF 'A_INDEX' (NON-UNIQUE) (Cost=1 Card=1)
    sql>select count(*)
      2    from a
      3   where object_name = 'x'   
      4     and object_id = 1;
    COUNT(*)
            0
    1 row selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1 Bytes=29)
       1    0   SORT (AGGREGATE)
       2    1     TABLE ACCESS (BY INDEX ROWID) OF 'A' (Cost=1 Card=1 Bytes=29)
       3    2       INDEX (RANGE SCAN) OF 'A_INDEX' (NON-UNIQUE) (Cost=1 Card=1)

  • Changing the order of columns in a table

    Can anyone tell me how to change the order of column in a table.
    I want a new column to be added in a table in 2nd position.
    Is there any way out for it?

    1) Does this have something to do with security? If not, it really ought to be posted in a more appropriate forum (Database - General for example).
    2) Why? If you care about the order of columns in a table, you're almost certainly doing something wrong. You can control the order of columns in a view, however, so you can put a view layer on top of the table to present the columns in a friendly fashion.
    3) Not without recreating the table. You can use the DBMS_REDEFINITION package to recreate the table with zero or minimal downtime but behind the scenes, you're really just creating a new table, copying the data over, dropping the old table, and renaming the new table to use the old table's name. DBMS_REDEFINITION does some extra work to track changes so that the original table can be available until the last possible moment.
    Justin

  • Change the order of columns in a report

    hi all.
    i can't change the order of columns in a report not just by altering the select statement. where can i change it?
    thanks.

    hi master
    sir i use 6i report i see full report but i culd not found
    report region and report attributes
    sir please give me step or idea or tree where report region and report attrinutes"
    thanking you
    aamir

  • How do I change the order of columns in the responses table?

    How do i change the order of columns in the responses table in FormsCentral?  The default setting puts them in reverse order!

    Hi,
    The issue with the default ordering of columns in the response table is something that we hope to address in the next update to FormsCentral. In the meantime, you can reorder the columns by selecting them then click/drag using the gray area above the column name. As shown below, an orange marker will show you where the columns will be placed when you release the mouse button.
    Sorry for the inconvenience.
    Regards,
    Brian

  • Does the Order of the tablesjoins in Where clause matter in ORDERED hint?

    The ORDERED hint requests that the tables listed in the FROM clause of a SQL statement be joined in the order specified. But does the order of the join in "where" clause matters?
    Will be there any performance difference between below query? The order of the table in the FROM clause remains the same, but there is a difference in the order of conditions in the WHERE clause
    SELECT /*+ ORDERED */ a.fp_i f
    FROn iw_owner.revenue_fpct b,
    dw_owner.fp_dinn c,
    dw_owner.nanaged_at_dinn a,
    dw_owner.at_dinn_curr d,
    iw_owner.na_progran e,
    dw_owner.fp_dinn_curr f,
    dw_owner.fpn_of_at_dinn g
    WHERE a.nacc_dinn_i = b.nacc_dinn_i
    AND b.fp_dinn_i = c.fp_dinn_i
    AND a.acc_i = d.acc_i
    AND a.acc_nacc_c = e.npn_pro_c
    AND a.fp_i = f.fp_i
    AND b.org_fpn_dinn_i = g.org_fpn_dinn_i(+)
    AND c.fp_i IN ('JG 04')
    AND b.dte_dinn_i BETWEEN '1-Apr-2011' and '30-Apr-2011'
    SELECT /*+ ORDERED */ a.fp_i f
    FROn iw_owner.revenue_fpct b,
    dw_owner.fp_dinn c,
    dw_owner.nanaged_at_dinn a,
    dw_owner.at_dinn_curr d,
    iw_owner.na_progran e,
    dw_owner.fp_dinn_curr f,
    dw_owner.fpn_of_at_dinn g
    WHERE c.fp_i IN ('JG 04')
    AND b.dte_dinn_i BETWEEN '1-Apr-2011' and '30-Apr-2011'
    AND b.fp_dinn_i = c.fp_dinn_i
    AND a.nacc_dinn_i = b.nacc_dinn_i
    AND a.acc_i = d.acc_i
    AND a.acc_nacc_c = e.npn_pro_c
    AND a.fp_i = f.fp_i
    AND b.org_fpn_dinn_i = g.org_fpn_dinn_i(+)
    Thanks

    Gangadhar Reddy wrote:
    Does it matter the order of first 2 tables?This question makes me really wonder. It's fairly easy to see how explain changes when using hints.
    Your question indicates that you do not look at explain plans?
    Then why are you asking about hints in the first place?
    Using hints is something you do when you want to force a specific execution plan as part of some investigation, because you know something that the optimizer does no, or you have found a bug in the optimizert.
    In all cases you know exactly what you are doing.
    The /*+ ORDERED */ is all about you telling the optimizer to join the tables in the order you specified them in the from clause.
    As to your original question, there exists a similar ORDERED_PREDICATES hint.
    Regards
    Peter

  • What is the order of Column Names in Sqlite query results?

    I am writing an application using Adobe Air, Sqlite, and Javascript.
    After writing the following select statement:
              SELECT field1, field 2, field 3, field 4 FROM TableA;
    I would like to get the columnName/data combination from each row -- which I do successfully with a loop:
              var columnName="";
              for (columnName in selResults.data[i]) {
                   output+=columnName + ":" + selResultsdata[i][columnName] + ";";
    My issue is that the column names come out in a different order every time I run the query and never once have they come out in the desired order -- field 1, field 2, field 3, field 4.  If I run the query in Firefox's Sqlite Manager, the columns come out in the "proper" order. When I run them in Adobe Air, the order will be the same if I run the query mulitple times without closing the app.  If I make a change such as declaring the columnName variable with "" before the for column, or declare it as (var = columnName in selResults.data) , then the order changes.  If I shut down my app and re-open after lunch and run query, it comes out in another order.  At this time, I'm not interested in the order of the rows, just the order of the columns in each output row.  I've even tried assiging an index to columnName which seems to just pick up a single letter of the columnName.
    I'm in the process of changing my HTML presentation of the data to assign a precise columnName to an HTML table title, but I'm reluctant to let go of the above concept as I think my separation of HTML/presentation and Javascript would be better if I could use the solution described above.
    So, does anybody know how to force the order of the columnNames in my output -- or what I'm doing to cause it to come out in a different order?
    Jeane

    Technically there isn't any "order" for the return columns. They aren't returned as an Array -- they're just properties on an Object instance (a "generic object"). The random order you're seeing is the behavior of the for..in loop iterating over the properties of the object. Unfortunately, with a for..in loop there is no guaranteed order for iterating over properties (and, as you've seen, it tends to vary wildly).
    The only solution is to create your own list of the column names and sort it the way you want to, then use that to create your output. For example, use the for..in loop to loop over the properties, but rather than actually get the values, just dump the column names into an Array:
    var columnName="";
    var columns = [];
    for (columnName in selResults.data[i]) {
        columns.push(columnName);
    columns = columns.sort(); // just uses the default alphabetical sort -- you would customize this if desired
    var j = 0;
    for (j = 0; j < columns.length; j++) {
        columnName = columns[j];
        output+=columnName + ":" + selResultsdata[i][columnName] + ";";

  • How to change the order of columns in a speadsheet?

    It seems this would be completely straight-forward. However I can find nothing in help to tell me how to do this. I am using a spreadsheet for data so want to be able to rearrange in the order of the columns. How does one do this?
    Thanks.
    John

    I don't want to move or sort the data. What I want
    to do is change the order of the columns. I have
    columns A through P. I want to move columns M, N,
    O, and P to come after A and B so I can see the
    information in these 6 columns in one glance.
    How does one do that?
    One doesn't, but there are altenatives.
    1.
    Select columns C..L by clicking and dragging across the column headers.
    Go Format (menu) > Column width.
    Set the width to 0 (zero) and click OK.
    This hides columns C..L, showing A, B, M, N, O, P...
    You can still enter data into cells in columns C..L by clicking on a cell in column B, then pressing tab to move through the hidden columns.
    To restore the display, select columns B..M then reset the column width to a visible value (the current width of column B will be the default).
    2.
    Copy the values in columns A, B, M, N, O, and P into a set of contiguous columns. Set a New View to show these columns in a separate window.
    Example:
    Go Window > New View
    Drag the new window that opens up and left to cover the initial window.
    In AA1, enter =A1
    Select AA1..AB1 then Fill right (command-R)
    In AC1, enter =M1
    Select AC1..AF1 then Fill right
    Select AA1..AFn where n is the last row in which you have data then Fill down (command-D)
    This copies the contents of the cells you want to view together into a set of cells that are together. You can view them by going to the Window menu and switching between the two views of the same spreadsheet. Or you can skip the step of creating a second View, and scroll from one location in the sheet to the other.
    The usual caveat applies: Anytime you're making extensive changes to a document, work with a COPY and keep the original as a backup you can revert to should a misstep along the way result in data loss.
    Regards,
    Barry

  • Capture Sharpening & Lens Corrections- Does the order matter?

    Okay, I think I understand the concept that all of the changes made in Lightroom are metadata edits, and so it does not matter what order you make changes to your image. So using the lightroom controls for sharpening and lens corrections (chromatic aberration, etc.) is just fine.
    But what if you are doing your capture sharpening outside of lightroom, say using photokit sharpener in photoshop?
    Does the use of the lens correction tools in lightroom negatively affect the capture sharpening done later in photoshop? Ideally I'd like to do all of the possible image adjustments in lightroom, without doing any sharpening, and then head over to photoshop for capture sharpening and any further photoshopping that is necessary.
    But if I do lens correction changes in lightroom, will that cause a problem? Do I need to forego doing any lens correcting in lightroom if I am going to be doing capture sharpening in photoshop after the fact?
    Thanks for the help.

    I shoot in Raw. I only recently got Photokit Sharpener, so I am trying to work that in to my workflow, in which case I would turn off Lightroom's default sharpening.
    I think I may be worried about something that isn't really a problem, but I had heard that when you adjust for chromatic aberrations, it adjusts the color channels, for example moving the red channel in relation to the blue channel, in order to eliminate the color fringing. If that is the case, then I was wondering whether sharpening applied outside of Lightroom would have to be applied after the chromatic aberration adjustments had been made or if it could be applied before without causing problems.
    My current plan is to just apply the capture sharpening in Photoshop after all LR adjustments have been made, and hopefully that will work out fine.

  • How to change the order of columns displayed in Stacked Canvas

    Dear Member,
    I have a Stacked Cavas which has many Items. How do i change the order of the Items displayed when the form is opened?
    I checked the X-Position in the property palette of each item, all the items have an X-position=0. I am really confused how do i change the order of the columns which are displayed in the stacked canvas when opening the form.
    Any help is greatly appreciated.
    Thanks
    Sandeep

    If i Try to use SET_ITEM_PROPERTY('BLOCK.ITEM', X_POS, myXpos);
    then it will increment each item X Position. The Total Stacked Canvas width i have is 9 and there are total of 36 items in the stacked canvas each of equal width 1.1,
    so the total becomes 38.5 which is greater than 9.
    I saw all triggers in the code, i dont see any code which exclusively determines item positions at run time. As i said before all the items have X position as zero but still they come up nicely.
    i HAVE A button in the form and following is the code which is written in when-button pressed trigger :
    show_view('DETAIL_CNT');
    GO_BLOCK('XX_PA_BUDGET_DTL_BLK');
    where DETAIL_CNT is the content canvas and 'XX_PA_BUDGET_DTL_BLK' is the data block in which items from both stacked and content exsist.
    I dont understand why this is happening.
    Thanks
    Sandeep

  • How to control the order in which records get indexed

    Hi,
    I like to control the order in which the ATG (10.1.2) product records get indexed in Endeca (3.1.1). I like the products/categories to be indexed in the order in which they are sequenced in BCC (in otherwords baseed on the sequence num they have). How to do this? Please help

    If you want TopLink to set the values in a particular order you can order the mappings on a descriptor by setting their ‘weight’ (DatabaseMapping.setWeight(int). All DirectToField type mappings are defaulted to a weight of 1 and all relationship mappings are defaulted to a weight of MAX_INTEGER. Mappings with a lower weight value will be processed first by TopLink.
    --Gordon

  • The order of columns in the report/drill down

    By using the command SAPBWGetDataProvider I can get a list of characteristics/structures and whether they are in the rows or columns but.....
    Is there any way to see the order, IE is there any way to extract the information to say Material Type is in the first column, Plant is in the second column etc....?
    Any help will be appreciated.
    Cheers
    Shep.

    FYI: Found the answer, it was in position 19 if position 4 is filled with an X(Row) or Y(Column).
    Shep.
    Message was edited by: Neal Sheppard

  • Specifying the order of column in Excel file

    How to specify the order of the columns in excel when data is exported from a table to excel.For eg. I have 2 columns in a table i.e. Base Location and Employee Number.When I export this data to the excel file the columns are displayed according to the alphabetical order i.e. Base Location first and then Employee Number. Whereas I want Employee Number column to be displayed first and then the Base Location column.
    Can anyone help me on this?

    Hi Sowmya,
    when you refer to my Excel Export tutorial on SDN: <a href="https://wiki.sdn.sap.com/wiki/x/0mQ">Exporting Table Data Using On-Demand Streams - SAP NetWeaver 7.0</a>:
    use <b>LinkedHashMap</b> instead of <i>HashMap</i>:
      private Map getProductColumnInfos() {
        Map columnInfosMap = new LinkedHashMap();
        columnInfosMap.put(IPrivateTableCompBasketView.IProductsElement.QUANTITY, "Quantity");
        columnInfosMap.put(IPrivateTableCompBasketView.IProductsElement.ARTICLE, "Article");
        columnInfosMap.put(IPrivateTableCompBasketView.IProductsElement.COLOR, "Color");
        columnInfosMap.put(IPrivateTableCompBasketView.IProductsElement.PRICE, "Price in EURO");
        columnInfosMap.put(
          IPrivateTableCompBasketView.IProductsElement.TOTAL__PER__ARTICLE,
          "Total Per Article In Euro");
        return columnInfosMap;
    This keeps the order of key-displaytext-pairs passed by the client (table component) to the service (excel export component) stable.
    Regards, Bertram

  • Why does the order of photos differ in a Photocast...?

    Everytime I publish a Photocast, the photos are ordered differently than they are in the corresponding iPhoto album...
    Why is this?
    How can I make the Photocast publish the photos in the same order they are in in the album...?
    I'd imagine the ordering between the album and Photocast would be the same by default but it's not...
    Thanks...
    DUAL 2.7 G5 POWERMAC   Mac OS X (10.4.7)  

    VENAM1:
    I believe it because once put on the server they are sorted alphanumerically. So, if you want to get the to the same order as in your album you'll have to rename the acutal files sequentially before posting. That can only be done by exporting from an album to the desktop using the export option of "Use Album Name". The reimport the new files and use them to make your Photocast.
    The export will rename those files to album name-01.jpg, album-name-02.jpt, etc. These will be sorted correctly on the server.
    Do you Twango?

  • How to generate row_number for more than the no of records in the order by column?

    Hi All,
    I have a query which contains Order quantity, order date and Row_number as Id. The below code produces 15 records as well as row_number for those 15 records. But I need row number for the next 12 months too. That means I need 12 more records with row_number
    and Order month and order quantity empty.
    use [AdventureWorksDW2012]
    go
    SELECT
      SUM([OrderQuantity]) As OrderQuantity
     ,CONVERT(DATE,[OrderDate]) As OrderDate
     ,LEFT(d.[EnglishMonthName],3) + '-' + CONVERT(CHAR(4),YEAR([OrderDate])) As OrderMonth
     ,ROW_NUMBER() OVER(ORDER BY([OrderDate])) As Id
    FROM [dbo].[FactResellerSales] f
    JOIN [dbo].[DimProduct]   p ON f.ProductKey = p.ProductKey
    JOIN [dbo].[DimDate]   d ON f.OrderDateKey = d.DateKey
    WHERE OrderDate >= '2006-04-01' AND EnglishProductName = 'Road-650 Red, 60'
    GROUP BY p.[ProductKey], [OrderDate],[EnglishMonthName]
    How can I achieve it?
    Regards,
    Julie

    I got a solution for this.
    use [AdventureWorksDW2012]
    go
    declare @min int, @max int
    IF OBJECT_ID('Tempdb..#tmp') IS NOT NULL
     drop table #tmp
    create table #tmp
       Id int
      ,OrderQuantity int
      ,OrderDate date
      ,OrderMonth varchar(78)
    insert into #tmp
     Id
    ,OrderQuantity
    ,OrderDate
    ,OrderMonth
    SELECT
      ROW_NUMBER() over(order by(orderdate)) As id
     ,SUM([OrderQuantity]) As OrderQuantity
     ,CONVERT(DATE,[OrderDate]) As OrderDate
     ,LEFT(d.[EnglishMonthName],3) + '-' + CONVERT(CHAR(4),YEAR([OrderDate])) As OrderMonth
    FROM [dbo].[FactResellerSales] f
    JOIN [dbo].[DimProduct]   p ON f.ProductKey = p.ProductKey
    JOIN [dbo].[DimDate]   d ON f.OrderDateKey = d.DateKey
    WHERE OrderDate >= '2006-04-01' AND EnglishProductName = 'Road-650 Red, 60'
    GROUP BY p.[ProductKey], [OrderDate],[EnglishMonthName]
    --select * from #tmp
    select @min=count(*)+1, @max=count(*)+12 from #tmp
    --select @min, @max
    IF OBJECT_ID('Tempdb..#tmp_table') IS NOT NULL
     drop table #tmp_table
    Create table #tmp_table
       Id int
      ,OrderQuantity int
      ,OrderDate date
    insert into #tmp_table
     select Id, OrderQuantity, OrderDate from #tmp
    --select * from #tmp_table
    declare @test varchar(1000)
    set @test='insert #tmp_table(id) select TOP '+ convert(varchar,@total)+' ROW_NUMBER() over(order by(select 1)) from sys.columns'
    exec(@test)
    while(@max >= @min)
    begin
     insert #tmp_table(id,OrderDate)
     select  @min,DATEADD(mm,1,max(orderdate))
     from #tmp_table
     set @min=@min+1
    end
    select * from #tmp_table
    Regards,
    Julie

Maybe you are looking for