Covering Indexes

Hi,
I have two sets of conditions that I use in where clause to query my table:
Select * from table1 where c1=’xx’ and c2=’xx’ and c3=’xx’
Select * from table1 where c1=’xx’ and c2=’xx’ and c4=’xx’
At this point I have this set of indexes on my table to cover the conditions in the where clause:
CREATE INDEX table1_idx1 ON table1 (c1,c2,c3)
CREATE INDEX table1_idx1 ON table1 (c1,c2,c4)
Is this the best index combinations to cover both where clauses? Can I do that with just one index?
Thank you,
Alan

Without more information, the best answer we can give is "maybe".
Having two indexes like this probably maximizes the efficiency of the two queries. It also maximizes the cost of inserts or updates on the underlying table and maximizes the amount of data stored in indexes.
Your one-index options will generally be less efficient for at least one of the two queries, but will reduce the cost of inserts and updates and reduce storage requirements. There are a number of one-index options depending on the Oracle version (and CBO settings), the selectivity of c3 and c4, the relative frequency and importance of the two queries, etc.
Justin

Similar Messages

  • Indexing and Deadlock in SQL Server 2008?

    All,
    I am running into a deadlock in SQL Server 2008. Using a profiler I was able to determine that the deadlock happens as I am trying to select and update row(S) in table in 2 different sessions.
    The select query from the profiler is shown below
    select
    nodeinstan0_.id as id35_,
    nodeinstan0_.BPMN_ELEMENT_ID as BPMN2_35_,
    nodeinstan0_.END_DATE as END3_35_,
    nodeinstan0_.NODE_ID as NODE4_35_,
    nodeinstan0_.NODE_INSTANCE_ID as NODE5_35_,
    nodeinstan0_.NODE_NAME as NODE6_35_,
    nodeinstan0_.PROCESS_INSTANCE_ID as PROCESS7_35_,
    nodeinstan0_.START_DATE as START8_35_
    from
    NODE_INSTANCE_LOG nodeinstan0_ where
    nodeinstan0_.NODE_INSTANCE_ID= @P0 and
    nodeinstan0_.PROCESS_INSTANCE_ID= @P1 and
    (nodeinstan0_.END_DATE is null)
    My SQL Scripts for creating the table and index is show below
    CREATE TABLE [dbo].[NODE_INSTANCE_LOG](
    [id] [numeric](19, 0) IDENTITY(1,1) NOT NULL,
    [BPMN_ELEMENT_ID] [varchar](255) NULL,
    [END_DATE] [datetime] NULL,
    [NODE_ID] [varchar](255) NOT NULL,
    [NODE_INSTANCE_ID] [varchar](255) NOT NULL,
    [NODE_NAME] [varchar](2000) NULL,
    [PROCESS_INSTANCE_ID] [numeric](19, 0) NOT NULL,
    [START_DATE] [datetime] NULL,
    PRIMARY KEY CLUSTERED
    [id] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
    IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
    ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    CREATE NONCLUSTERED INDEX IX_NODE_INSTANCE_LOG_Index1
    ON NODE_INSTANCE_LOG(NODE_INSTANCE_ID, PROCESS_INSTANCE_ID, END_DATE)
    INCLUDE
    ( ID, BPMN_ELEMENT_ID, NODE_ID, NODE_NAME, START_DATE);
    As I understood from number of other forums and blogs - I have included the columns under the where clause in the "COVERING index" and the rest of the columns from the select query under non clustered Index. But I am still facing a deadlock.
    Would appreciate if some once can point me in the right direction.
    regards D

    Correction to my earlier observation. Its not a select/update that's causing the deadlock but its a select/select
    I am pasting an extract from the Tracer
    <deadlock victim="process6a9048">
    <process-list>
    <process id="process6a9048" taskpriority="0" logused="15888" waitresource="KEY: 6:72057594142588928 (fbd2e857cffa)" waittime="812" ownerId="1927048" transactionname="implicit_transaction" lasttranstarted="2014-01-03T17:01:35.453" XDES="0x91cd7960" lockMode="S" schedulerid="2" kpid="3640" status="suspended" spid="56" sbid="0" ecid="0" priority="0" trancount="1" lastbatchstarted="2014-01-03T17:01:35.723" lastbatchcompleted="2014-01-03T17:01:35.723" clientapp="jTDS" hostname="LDN-LRM-PC-189" hostpid="123" loginname="username" isolationlevel="read committed (2)" xactid="1927048" currentdb="6" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
    <executionStack>
    <frame procname="adhoc" line="1" stmtstart="62" sqlhandle="0x02000000e82b4000ebf38fb66978d5f9f2314a6046f957b3">
    select nodeinstan0_.id as id35_, nodeinstan0_.BPMN_ELEMENT_ID as BPMN2_35_, nodeinstan0_.END_DATE as END3_35_, nodeinstan0_.NODE_ID as NODE4_35_, nodeinstan0_.NODE_INSTANCE_ID as NODE5_35_, nodeinstan0_.NODE_NAME as NODE6_35_, nodeinstan0_.PROCESS_INSTANCE_ID as PROCESS7_35_, nodeinstan0_.START_DATE as START8_35_ from NODE_INSTANCE_LOG nodeinstan0_ where nodeinstan0_.NODE_INSTANCE_ID= @P0 and nodeinstan0_.PROCESS_INSTANCE_ID= @P1 and (nodeinstan0_.END_DATE is null) </frame>
    </executionStack>
    <inputbuf>
    (@P0 nvarchar(4000),@P1 bigint)select nodeinstan0_.id as id35_, nodeinstan0_.BPMN_ELEMENT_ID as BPMN2_35_, nodeinstan0_.END_DATE as END3_35_, nodeinstan0_.NODE_ID as NODE4_35_, nodeinstan0_.NODE_INSTANCE_ID as NODE5_35_, nodeinstan0_.NODE_NAME as NODE6_35_, nodeinstan0_.PROCESS_INSTANCE_ID as PROCESS7_35_, nodeinstan0_.START_DATE as START8_35_ from NODE_INSTANCE_LOG nodeinstan0_ where nodeinstan0_.NODE_INSTANCE_ID= @P0 and nodeinstan0_.PROCESS_INSTANCE_ID= @P1 and (nodeinstan0_.END_DATE is null) </inputbuf>
    </process>
    <process id="process6dddc8" taskpriority="0" logused="114316" waitresource="KEY: 6:72057594142588928 (44ec7e8e62c7)" waittime="602" ownerId="1927022" transactionname="implicit_transaction" lasttranstarted="2014-01-03T17:01:35.227" XDES="0x91d25950" lockMode="S" schedulerid="4" kpid="17412" status="suspended" spid="60" sbid="0" ecid="0" priority="0" trancount="1" lastbatchstarted="2014-01-03T17:01:35.937" lastbatchcompleted="2014-01-03T17:01:35.937" clientapp="jTDS" hostname="LDN-LRM-PC-189" hostpid="123" loginname="username" isolationlevel="read committed (2)" xactid="1927022" currentdb="6" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
    <executionStack>
    <frame procname="adhoc" line="1" stmtstart="62" sqlhandle="0x02000000e82b4000ebf38fb66978d5f9f2314a6046f957b3">
    select nodeinstan0_.id as id35_, nodeinstan0_.BPMN_ELEMENT_ID as BPMN2_35_, nodeinstan0_.END_DATE as END3_35_, nodeinstan0_.NODE_ID as NODE4_35_, nodeinstan0_.NODE_INSTANCE_ID as NODE5_35_, nodeinstan0_.NODE_NAME as NODE6_35_, nodeinstan0_.PROCESS_INSTANCE_ID as PROCESS7_35_, nodeinstan0_.START_DATE as START8_35_ from NODE_INSTANCE_LOG nodeinstan0_ where nodeinstan0_.NODE_INSTANCE_ID= @P0 and nodeinstan0_.PROCESS_INSTANCE_ID= @P1 and (nodeinstan0_.END_DATE is null) </frame>
    </executionStack>
    <inputbuf>
    (@P0 nvarchar(4000),@P1 bigint)select nodeinstan0_.id as id35_, nodeinstan0_.BPMN_ELEMENT_ID as BPMN2_35_, nodeinstan0_.END_DATE as END3_35_, nodeinstan0_.NODE_ID as NODE4_35_, nodeinstan0_.NODE_INSTANCE_ID as NODE5_35_, nodeinstan0_.NODE_NAME as NODE6_35_, nodeinstan0_.PROCESS_INSTANCE_ID as PROCESS7_35_, nodeinstan0_.START_DATE as START8_35_ from NODE_INSTANCE_LOG nodeinstan0_ where nodeinstan0_.NODE_INSTANCE_ID= @P0 and nodeinstan0_.PROCESS_INSTANCE_ID= @P1 and (nodeinstan0_.END_DATE is null) </inputbuf>
    </process>
    </process-list>
    <resource-list>
    <keylock hobtid="72057594142588928" dbid="6" objectname="reform.dbo.NODE_INSTANCE_LOG" indexname="IX_NODE_INSTANCE_LOG_Index1" id="lock89f43000" mode="X" associatedObjectId="72057594142588928">
    <owner-list>
    <owner id="process6dddc8" mode="X"/>
    </owner-list>
    <waiter-list>
    <waiter id="process6a9048" mode="S" requestType="wait"/>
    </waiter-list>
    </keylock>
    <keylock hobtid="72057594142588928" dbid="6" objectname="reform.dbo.NODE_INSTANCE_LOG" indexname="IX_NODE_INSTANCE_LOG_Index1" id="lock81b22a80" mode="X" associatedObjectId="72057594142588928">
    <owner-list>
    <owner id="process6a9048" mode="X"/>
    </owner-list>
    <waiter-list>
    <waiter id="process6dddc8" mode="S" requestType="wait"/>
    </waiter-list>
    </keylock>
    </resource-list>
    </deadlock>
    Would appreciate if some one can point out where the issue is.

  • Select distinct is using the wrong index

    Hello,
    I have an indexes question?
    I have a table with 1M rows, the table structure is as follows:
    create table X(aTime DATE , a1 NUMBER(28,0), a2 NUMBER(28,0), a3 NUMBER(28,0), .... , a20 NUMBER(28,0) );
    I have also 2 indexes:
    - IDX1 is defined on (aTime, a1, a2, a3).
    - IDX2 is defined on (a1, a2, a3).
    I run the following query: "SELECT DISTINCT A1, A2, A3 from X;" and see that the optimizer chooses to do a FTS (full table scan) though I was expecting him to use IDX2 because it looks like a "covering" indexes giving all the answers to the query without fetching data rows.
    When I try to force him to use indexes, using the following hint "/*+INDEX(X IDX2)*/" the optimizer chooses IDX1.
    When I use same hint after I dropped IDX1 the optimizer still prefers to make FTS .
    Some general info:
    - a1, a2 and a3 have about 500 distinct values each).
    - db version 8.1.7.4.
    - all tables and indexes are analyzed.
    I have two questions:
    ===============
    1.
    Why does the optimizer prefers IDX1 (aTime, a1, a2, a3) over IDX2 (a1, a2, a3) when the query specifically requests distinct values of (aTime, a1, a2, a3), isn't there a shortcut the optimizer should use here?
    2.
    When I request the optimizer to use specific index (using hints), shouldn't it use the index I request regardless of his calculations? If not, is there any way to change this behavior?
    Tal Olier
    [email protected]

    You said you analyzed the tables and indexes. Did you also analyze the indexed columns?
    A full table scan may be a better execution plan than using an index, especially if you are selecting the full table.
    Remember that a hint is jut that, a hint. It suggests to the optimizer to do something, but the optimizer may still choose a different plan.

  • Multiple indexes on a table with various combinations

    Hi Experts,
    This post is similar to my previous one on indexing. am just trying to understand proper indexing strategy.
    Assuming that i have to use following queries frequently.
    select Col1, Col2, Col3 from tab where col4='some value'
    select Col1, Col2, Col3 from tab where col5='some value'
    select Col1, Col2, Col3 from tab where col6='some value'
    select Col1, Col2, Col3 from tab where col7='some value'
    select Col1, Col2, Col3 from tab where col8='some value'
    select Col1, Col2, Col3 from tab where col9='some value'
    select Col1, Col2, Col3 from tab where col10='some value'
    here, my doubt is, do we need to create "1 clustered + 6 NC covering" indexes (total 7) as we have 7 different columns in the where clause in 7 different select statements? Or, is there any better way of doing this?
    Thanks,
    Shiva

    >am just trying to understand proper indexing strategy.
    There is no such a thing. It is an art.
    Generally you can use covering index for a business critical query. But that may slow down other queries because the covering index usually wide! You need to
    check the execution plans for each query involved.
    It is better to apply narrow fast indexes that way other queries will not slow.
    Remember STATISTICS! It should be updated nightly:
    http://www.sqlusa.com/articles/query-optimization/
    The database engine uses the STATISTICS for the execution plan preparation not the index.
    For best performance the indexes should be narrow (fast) and STATISTICS up-to-date.
    Missing/fragmented/wide indexes & out-of-date STATISTICS are detrimental for performance.
    Kalman Toth Database & OLAP Architect
    SELECT Video Tutorials 4 Hours
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Oracle Index Search

    We are on 11.1.0.7
    I am looking for some inputs from someone who has already seen this behavior.
    We have two identical schemas, and an identical table in each of this schema with same in structure and around 8 indexes on these tables.
    For one schema, there is a covering index and we have kept it in the KEEP pool.
    But when I am running the same SQL against each of this schema, while looking at the explain plan, it shows that in one case (surprisingly the one that was not in KEEP pool) it is reading from this covering index and in second case where we have that covering index in KEEP buffer pool, it is NOT reading from the covering index.
    What can be the reason for this behavior? Why a same structure table and with around same amount of data is showing a different plan? In one case it is looking into Covering Index and in other it is not.
    Thanks!

    select clustering_factor from dba_indexes where owner=[SCHEMA1] and index_name='[INDEX]';
    CLUSTERING_FACTOR
              1643019
    select clustering_factor from dba_indexes where owner=[SCHEMA2] and index_name='[INDEX]';
    CLUSTERING_FACTOR
              1038427Looks like in SCHEMA1, oracle is doing one extra step of looking intio the primary key instead of this Covering index to fetch the result.

  • Merging Multiple Rows into a single Row

    I've read a number of posts with no real good answers or answers that might be good for tables with 3 columns of data. I have a table with 33 columns that will all need to be combined. A little history. Apparently in production the Primary Key Constraint
    was dropped which allowed some duplicate data into the table. Now they want me to squish the records together to fix it.
    Sorry I couldn't include the screen shot of the data, MSDN says my account isn't verified...
    My requirements when I'm putting them together, CERElibilityID is a unique column. This is a sticky problem because in the related tables it is only one of the parent records gets child records related to it.
     I just want to keep the one that has the child records in CERPrepActivity table. If there are no child records then the rule will be like all the other records with data. 
    If a  field is null and another record has data we take the record that has data.
    If multiple records have data we take the record that has the highest "ModifiedOn" timestamp column value.
    I feel like I'm asking a lot, but I'm in a bit of a bind and I've spent the morning Googling and have come up with nothing 
    Thank  you for any help the community can provide and the more specific you can be the better. I'm not a DBA or SQL guru by any stretch so I'm way out of my element.
    Thanks

    Using the systables, you can get information about your table. I put these together:
    SELECT '
    LEFT OUTER JOIN #CEREligibility ['+c.name+']
    ON s.caseID = ['+c.name+'].caseID
    AND s.modifiedOn = ['+c.name+'].modifiedOn
    AND ['+c.name+'].['+c.name+'] = (SELECT TOP 1 ['+c.name+'] FROM #CEREligibility WHERE caseID = s.caseID AND ['+c.name+'] IS NOT NULL ORDER BY ModifiedOn)
    AND ['+c.name+'].['+c.name+'] IS NOT NULL'
    FROM tempdb.sys.objects o
    INNER JOIN tempdb.sys.columns c
    ON o.object_id = c.object_id
    AND o.name LIKE '#CEREligibility%'
    SELECT '['+c.name+'].['+c.name+'] AS ['+c.name+'], '
    FROM tempdb.sys.objects o
    INNER JOIN tempdb.sys.columns c
    ON o.object_id = c.object_id
    AND o.name LIKE '#CEREligibility%'
    On my test system I created your table as a temp table named #CEREligibility.
    The first of these two queries generates LEFT OUT JOIN SQL for a self join. Because we're using the columns systable, a LOJ for each column is generated.
    The second, produces a select list.
    Putting the two together like so, and adding a FROM and GROUP BY gives us:
    SELECT
    MAX([CEREligibilityId].[CEREligibilityId]) AS [CEREligibilityId], s.[CaseId], MAX([M2Eligibility].[M2Eligibility]) AS [M2Eligibility], MAX([CDREligibility].[CDREligibility]) AS [CDREligibility], MAX([M2Comments].[M2Comments]) AS [M2Comments], MAX([M2CommentsRtf].[M2CommentsRtf]) AS [M2CommentsRtf], MAX([CDRComments].[CDRComments]) AS [CDRComments], MAX([CDRCommentsRtf].[CDRCommentsRtf]) AS [CDRCommentsRtf], MAX([RIAWA].[RIAWA]) AS [RIAWA], MAX([RIAWADate].[RIAWADate]) AS [RIAWADate], MAX([EducationAndTraining].[EducationAndTraining]) AS [EducationAndTraining], MAX([EducationAndTrainingDate].[EducationAndTrainingDate]) AS [EducationAndTrainingDate], MAX([Internship].[Internship]) AS [Internship], MAX([InternshipDate].[InternshipDate]) AS [InternshipDate], MAX([Apprenticeship].[Apprenticeship]) AS [Apprenticeship], MAX([ApprenticeshipDate].[ApprenticeshipDate]) AS [ApprenticeshipDate], MAX([Entrepreneurship].[Entrepreneurship]) AS [Entrepreneurship], MAX([EntrepreneurshipDate].[EntrepreneurshipDate]) AS [EntrepreneurshipDate], MAX([EmploymentPrep].[EmploymentPrep]) AS [EmploymentPrep], MAX([EmploymentPrepDate].[EmploymentPrepDate]) AS [EmploymentPrepDate], MAX([OTPrep].[OTPrep]) AS [OTPrep], MAX([OTPrepDate].[OTPrepDate]) AS [OTPrepDate], MAX([ExitInterview].[ExitInterview]) AS [ExitInterview], MAX([ExitInterviewDate].[ExitInterviewDate]) AS [ExitInterviewDate], MAX([CreatedOn].[CreatedOn]) AS [CreatedOn], MAX([CreatedBy].[CreatedBy]) AS [CreatedBy], MAX([ModifiedOn].[ModifiedOn]) AS [ModifiedOn], MAX([ModifiedBy].[ModifiedBy]) AS [ModifiedBy], MAX([BCPermInEligibility].[BCPermInEligibility]) AS [BCPermInEligibility], MAX([CCPermInEligibility].[CCPermInEligibility]) AS [CCPermInEligibility], MAX([M2EligibilityDate].[M2EligibilityDate]) AS [M2EligibilityDate], MAX([CDREligibilityDate].[CDREligibilityDate]) AS [CDREligibilityDate], MAX([ExitSeparationCode].[ExitSeparationCode]) AS [ExitSeparationCode], MAX([ExitSeparationSubCode].[ExitSeparationSubCode]) AS [ExitSeparationSubCode]
    FROM #CEREligibility s
    LEFT OUTER JOIN #CEREligibility [CEREligibilityId]
    ON s.caseID = [CEREligibilityId].caseID
    AND s.modifiedOn = [CEREligibilityId].modifiedOn
    AND [CEREligibilityId].[CEREligibilityId] = (SELECT TOP 1 [CEREligibilityId] FROM #CEREligibility WHERE caseID = s.caseID AND [CEREligibilityId] IS NOT NULL ORDER BY ModifiedOn)
    AND [CEREligibilityId].[CEREligibilityId] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CaseId]
    ON s.caseID = [CaseId].caseID
    AND s.modifiedOn = [CaseId].modifiedOn
    AND [CaseId].[CaseId] = (SELECT TOP 1 [CaseId] FROM #CEREligibility WHERE caseID = s.caseID AND [CaseId] IS NOT NULL ORDER BY ModifiedOn)
    AND [CaseId].[CaseId] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [M2Eligibility]
    ON s.caseID = [M2Eligibility].caseID
    AND s.modifiedOn = [M2Eligibility].modifiedOn
    AND [M2Eligibility].[M2Eligibility] = (SELECT TOP 1 [M2Eligibility] FROM #CEREligibility WHERE caseID = s.caseID AND [M2Eligibility] IS NOT NULL ORDER BY ModifiedOn)
    AND [M2Eligibility].[M2Eligibility] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CDREligibility]
    ON s.caseID = [CDREligibility].caseID
    AND s.modifiedOn = [CDREligibility].modifiedOn
    AND [CDREligibility].[CDREligibility] = (SELECT TOP 1 [CDREligibility] FROM #CEREligibility WHERE caseID = s.caseID AND [CDREligibility] IS NOT NULL ORDER BY ModifiedOn)
    AND [CDREligibility].[CDREligibility] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [M2Comments]
    ON s.caseID = [M2Comments].caseID
    AND s.modifiedOn = [M2Comments].modifiedOn
    AND [M2Comments].[M2Comments] = (SELECT TOP 1 [M2Comments] FROM #CEREligibility WHERE caseID = s.caseID AND [M2Comments] IS NOT NULL ORDER BY ModifiedOn)
    AND [M2Comments].[M2Comments] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [M2CommentsRtf]
    ON s.caseID = [M2CommentsRtf].caseID
    AND s.modifiedOn = [M2CommentsRtf].modifiedOn
    AND [M2CommentsRtf].[M2CommentsRtf] = (SELECT TOP 1 [M2CommentsRtf] FROM #CEREligibility WHERE caseID = s.caseID AND [M2CommentsRtf] IS NOT NULL ORDER BY ModifiedOn)
    AND [M2CommentsRtf].[M2CommentsRtf] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CDRComments]
    ON s.caseID = [CDRComments].caseID
    AND s.modifiedOn = [CDRComments].modifiedOn
    AND [CDRComments].[CDRComments] = (SELECT TOP 1 [CDRComments] FROM #CEREligibility WHERE caseID = s.caseID AND [CDRComments] IS NOT NULL ORDER BY ModifiedOn)
    AND [CDRComments].[CDRComments] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CDRCommentsRtf]
    ON s.caseID = [CDRCommentsRtf].caseID
    AND s.modifiedOn = [CDRCommentsRtf].modifiedOn
    AND [CDRCommentsRtf].[CDRCommentsRtf] = (SELECT TOP 1 [CDRCommentsRtf] FROM #CEREligibility WHERE caseID = s.caseID AND [CDRCommentsRtf] IS NOT NULL ORDER BY ModifiedOn)
    AND [CDRCommentsRtf].[CDRCommentsRtf] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [RIAWA]
    ON s.caseID = [RIAWA].caseID
    AND s.modifiedOn = [RIAWA].modifiedOn
    AND [RIAWA].[RIAWA] = (SELECT TOP 1 [RIAWA] FROM #CEREligibility WHERE caseID = s.caseID AND [RIAWA] IS NOT NULL ORDER BY ModifiedOn)
    AND [RIAWA].[RIAWA] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [RIAWADate]
    ON s.caseID = [RIAWADate].caseID
    AND s.modifiedOn = [RIAWADate].modifiedOn
    AND [RIAWADate].[RIAWADate] = (SELECT TOP 1 [RIAWADate] FROM #CEREligibility WHERE caseID = s.caseID AND [RIAWADate] IS NOT NULL ORDER BY ModifiedOn)
    AND [RIAWADate].[RIAWADate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [EducationAndTraining]
    ON s.caseID = [EducationAndTraining].caseID
    AND s.modifiedOn = [EducationAndTraining].modifiedOn
    AND [EducationAndTraining].[EducationAndTraining] = (SELECT TOP 1 [EducationAndTraining] FROM #CEREligibility WHERE caseID = s.caseID AND [EducationAndTraining] IS NOT NULL ORDER BY ModifiedOn)
    AND [EducationAndTraining].[EducationAndTraining] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [EducationAndTrainingDate]
    ON s.caseID = [EducationAndTrainingDate].caseID
    AND s.modifiedOn = [EducationAndTrainingDate].modifiedOn
    AND [EducationAndTrainingDate].[EducationAndTrainingDate] = (SELECT TOP 1 [EducationAndTrainingDate] FROM #CEREligibility WHERE caseID = s.caseID AND [EducationAndTrainingDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [EducationAndTrainingDate].[EducationAndTrainingDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [Internship]
    ON s.caseID = [Internship].caseID
    AND s.modifiedOn = [Internship].modifiedOn
    AND [Internship].[Internship] = (SELECT TOP 1 [Internship] FROM #CEREligibility WHERE caseID = s.caseID AND [Internship] IS NOT NULL ORDER BY ModifiedOn)
    AND [Internship].[Internship] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [InternshipDate]
    ON s.caseID = [InternshipDate].caseID
    AND s.modifiedOn = [InternshipDate].modifiedOn
    AND [InternshipDate].[InternshipDate] = (SELECT TOP 1 [InternshipDate] FROM #CEREligibility WHERE caseID = s.caseID AND [InternshipDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [InternshipDate].[InternshipDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [Apprenticeship]
    ON s.caseID = [Apprenticeship].caseID
    AND s.modifiedOn = [Apprenticeship].modifiedOn
    AND [Apprenticeship].[Apprenticeship] = (SELECT TOP 1 [Apprenticeship] FROM #CEREligibility WHERE caseID = s.caseID AND [Apprenticeship] IS NOT NULL ORDER BY ModifiedOn)
    AND [Apprenticeship].[Apprenticeship] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ApprenticeshipDate]
    ON s.caseID = [ApprenticeshipDate].caseID
    AND s.modifiedOn = [ApprenticeshipDate].modifiedOn
    AND [ApprenticeshipDate].[ApprenticeshipDate] = (SELECT TOP 1 [ApprenticeshipDate] FROM #CEREligibility WHERE caseID = s.caseID AND [ApprenticeshipDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [ApprenticeshipDate].[ApprenticeshipDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [Entrepreneurship]
    ON s.caseID = [Entrepreneurship].caseID
    AND s.modifiedOn = [Entrepreneurship].modifiedOn
    AND [Entrepreneurship].[Entrepreneurship] = (SELECT TOP 1 [Entrepreneurship] FROM #CEREligibility WHERE caseID = s.caseID AND [Entrepreneurship] IS NOT NULL ORDER BY ModifiedOn)
    AND [Entrepreneurship].[Entrepreneurship] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [EntrepreneurshipDate]
    ON s.caseID = [EntrepreneurshipDate].caseID
    AND s.modifiedOn = [EntrepreneurshipDate].modifiedOn
    AND [EntrepreneurshipDate].[EntrepreneurshipDate] = (SELECT TOP 1 [EntrepreneurshipDate] FROM #CEREligibility WHERE caseID = s.caseID AND [EntrepreneurshipDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [EntrepreneurshipDate].[EntrepreneurshipDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [EmploymentPrep]
    ON s.caseID = [EmploymentPrep].caseID
    AND s.modifiedOn = [EmploymentPrep].modifiedOn
    AND [EmploymentPrep].[EmploymentPrep] = (SELECT TOP 1 [EmploymentPrep] FROM #CEREligibility WHERE caseID = s.caseID AND [EmploymentPrep] IS NOT NULL ORDER BY ModifiedOn)
    AND [EmploymentPrep].[EmploymentPrep] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [EmploymentPrepDate]
    ON s.caseID = [EmploymentPrepDate].caseID
    AND s.modifiedOn = [EmploymentPrepDate].modifiedOn
    AND [EmploymentPrepDate].[EmploymentPrepDate] = (SELECT TOP 1 [EmploymentPrepDate] FROM #CEREligibility WHERE caseID = s.caseID AND [EmploymentPrepDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [EmploymentPrepDate].[EmploymentPrepDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [OTPrep]
    ON s.caseID = [OTPrep].caseID
    AND s.modifiedOn = [OTPrep].modifiedOn
    AND [OTPrep].[OTPrep] = (SELECT TOP 1 [OTPrep] FROM #CEREligibility WHERE caseID = s.caseID AND [OTPrep] IS NOT NULL ORDER BY ModifiedOn)
    AND [OTPrep].[OTPrep] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [OTPrepDate]
    ON s.caseID = [OTPrepDate].caseID
    AND s.modifiedOn = [OTPrepDate].modifiedOn
    AND [OTPrepDate].[OTPrepDate] = (SELECT TOP 1 [OTPrepDate] FROM #CEREligibility WHERE caseID = s.caseID AND [OTPrepDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [OTPrepDate].[OTPrepDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ExitInterview]
    ON s.caseID = [ExitInterview].caseID
    AND s.modifiedOn = [ExitInterview].modifiedOn
    AND [ExitInterview].[ExitInterview] = (SELECT TOP 1 [ExitInterview] FROM #CEREligibility WHERE caseID = s.caseID AND [ExitInterview] IS NOT NULL ORDER BY ModifiedOn)
    AND [ExitInterview].[ExitInterview] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ExitInterviewDate]
    ON s.caseID = [ExitInterviewDate].caseID
    AND s.modifiedOn = [ExitInterviewDate].modifiedOn
    AND [ExitInterviewDate].[ExitInterviewDate] = (SELECT TOP 1 [ExitInterviewDate] FROM #CEREligibility WHERE caseID = s.caseID AND [ExitInterviewDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [ExitInterviewDate].[ExitInterviewDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CreatedOn]
    ON s.caseID = [CreatedOn].caseID
    AND s.modifiedOn = [CreatedOn].modifiedOn
    AND [CreatedOn].[CreatedOn] = (SELECT TOP 1 [CreatedOn] FROM #CEREligibility WHERE caseID = s.caseID AND [CreatedOn] IS NOT NULL ORDER BY ModifiedOn)
    AND [CreatedOn].[CreatedOn] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CreatedBy]
    ON s.caseID = [CreatedBy].caseID
    AND s.modifiedOn = [CreatedBy].modifiedOn
    AND [CreatedBy].[CreatedBy] = (SELECT TOP 1 [CreatedBy] FROM #CEREligibility WHERE caseID = s.caseID AND [CreatedBy] IS NOT NULL ORDER BY ModifiedOn)
    AND [CreatedBy].[CreatedBy] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ModifiedOn]
    ON s.caseID = [ModifiedOn].caseID
    AND s.modifiedOn = [ModifiedOn].modifiedOn
    AND [ModifiedOn].[ModifiedOn] = (SELECT TOP 1 [ModifiedOn] FROM #CEREligibility WHERE caseID = s.caseID AND [ModifiedOn] IS NOT NULL ORDER BY ModifiedOn)
    AND [ModifiedOn].[ModifiedOn] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ModifiedBy]
    ON s.caseID = [ModifiedBy].caseID
    AND s.modifiedOn = [ModifiedBy].modifiedOn
    AND [ModifiedBy].[ModifiedBy] = (SELECT TOP 1 [ModifiedBy] FROM #CEREligibility WHERE caseID = s.caseID AND [ModifiedBy] IS NOT NULL ORDER BY ModifiedOn)
    AND [ModifiedBy].[ModifiedBy] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [BCPermInEligibility]
    ON s.caseID = [BCPermInEligibility].caseID
    AND s.modifiedOn = [BCPermInEligibility].modifiedOn
    AND [BCPermInEligibility].[BCPermInEligibility] = (SELECT TOP 1 [BCPermInEligibility] FROM #CEREligibility WHERE caseID = s.caseID AND [BCPermInEligibility] IS NOT NULL ORDER BY ModifiedOn)
    AND [BCPermInEligibility].[BCPermInEligibility] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CCPermInEligibility]
    ON s.caseID = [CCPermInEligibility].caseID
    AND s.modifiedOn = [CCPermInEligibility].modifiedOn
    AND [CCPermInEligibility].[CCPermInEligibility] = (SELECT TOP 1 [CCPermInEligibility] FROM #CEREligibility WHERE caseID = s.caseID AND [CCPermInEligibility] IS NOT NULL ORDER BY ModifiedOn)
    AND [CCPermInEligibility].[CCPermInEligibility] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [M2EligibilityDate]
    ON s.caseID = [M2EligibilityDate].caseID
    AND s.modifiedOn = [M2EligibilityDate].modifiedOn
    AND [M2EligibilityDate].[M2EligibilityDate] = (SELECT TOP 1 [M2EligibilityDate] FROM #CEREligibility WHERE caseID = s.caseID AND [M2EligibilityDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [M2EligibilityDate].[M2EligibilityDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CDREligibilityDate]
    ON s.caseID = [CDREligibilityDate].caseID
    AND s.modifiedOn = [CDREligibilityDate].modifiedOn
    AND [CDREligibilityDate].[CDREligibilityDate] = (SELECT TOP 1 [CDREligibilityDate] FROM #CEREligibility WHERE caseID = s.caseID AND [CDREligibilityDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [CDREligibilityDate].[CDREligibilityDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ExitSeparationCode]
    ON s.caseID = [ExitSeparationCode].caseID
    AND s.modifiedOn = [ExitSeparationCode].modifiedOn
    AND [ExitSeparationCode].[ExitSeparationCode] = (SELECT TOP 1 [ExitSeparationCode] FROM #CEREligibility WHERE caseID = s.caseID AND [ExitSeparationCode] IS NOT NULL ORDER BY ModifiedOn)
    AND [ExitSeparationCode].[ExitSeparationCode] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ExitSeparationSubCode]
    ON s.caseID = [ExitSeparationSubCode].caseID
    AND s.modifiedOn = [ExitSeparationSubCode].modifiedOn
    AND [ExitSeparationSubCode].[ExitSeparationSubCode] = (SELECT TOP 1 [ExitSeparationSubCode] FROM #CEREligibility WHERE caseID = s.caseID AND [ExitSeparationSubCode] IS NOT NULL ORDER BY ModifiedOn)
    AND [ExitSeparationSubCode].[ExitSeparationSubCode] IS NOT NULL
    GROUP BY s.caseID
    When I ran this against your test data, It produced a single row for each of the two case ID's.
    To keep performance in line, I also created a covering index on the temp table:
    CREATE INDEX idx_caseID_ModifiedOn ON #CEREligibility (caseID, modifiedOn) INCLUDE ([CEREligibilityId], [M2Eligibility], [CDREligibility], [M2Comments], [M2CommentsRtf], [CDRComments], [CDRCommentsRtf], [RIAWA], [RIAWADate], [EducationAndTraining], [EducationAndTrainingDate], [Internship], [InternshipDate], [Apprenticeship], [ApprenticeshipDate], [Entrepreneurship], [EntrepreneurshipDate], [EmploymentPrep], [EmploymentPrepDate], [OTPrep], [OTPrepDate], [ExitInterview], [ExitInterviewDate], [CreatedOn], [CreatedBy], [ModifiedBy], [BCPermInEligibility], [CCPermInEligibility], [M2EligibilityDate], [CDREligibilityDate], [ExitSeparationCode], [ExitSeparationSubCode])
    Don't forget to mark helpful posts, and answers. It helps others to find relevant posts to the same question.

  • Bug 2679062 - Wrong results possible from multi-column INLIST - though stat

    Hi,
    The following test case is supplied in the metalink in bug no. 2871341, the base bug for this bug is 2679062.
    REPRODUCIBILITY:
    Reproduces constantly with simple test case below:
    TEST CASE:
    DROP TABLE A1
    CREATE TABLE A1 (X1 VARCHAR2(10), X2 VARCHAR2(10))
    REM *********** Create the second table: ***************
    DROP TABLE A2
    CREATE TABLE A2 (X1 VARCHAR2(10), X2 VARCHAR2(10))
    INSERT INTO A1 VALUES ('1','2');
    INSERT INTO A2 VALUES ('3','4');
    COMMIT;
    CREATE INDEX A1_X1 ON A1(X1 );
    CREATE INDEX A1_X2 ON A1(X2);
    CREATE INDEX A2_X1 ON A2(X1);
    CREATE INDEX A2_X2 ON A2(X2);
    CREATE OR REPLACE VIEW A_ALL AS SELECT * FROM A1 UNION ALL SELECT * FROM A2;
    ANALYZE TABLE A1 COMPUTE STATISTICS;
    ANALYZE TABLE A2 COMPUTE STATISTICS;
    SELECT * FROM A_ALL;
    SELECT * FROM A_ALL WHERE (X1='1' AND X2='2') ;
    SELECT * FROM A_ALL WHERE ((X1='1' AND X2='2') OR (X1='3' AND X2='4'));
    The 2nd query returns answer while the second is not !
    The following is published in the 9.2.0.4 fixed bug list:
    " 9204 - 2679062 - Wrong results possible from multi-column INLIST "
    I have installed 9.2.0.4 patch set on a win 2000 machine Oracle and saw that the above case is actually solved but our application which has a very similar case doesn't.
    After investigating I found the following test case that fails, it reproduces only when you have index on all columns (covering index):
    drop table t1_1;
    drop table t1_2;
    create table t1_1(c1 number, c2 number, c3 number);
    create table t1_2(c1 number, c2 number, c3 number);
    create index t1_1_ix on t1_1(c1, c2, c3);
    create index t1_2_ix on t1_2(c1, c2, c3);
    create or replace view t1 as select * from t1_1 union all select * from t1_2;
    insert into t1_1 values(1, 2, 100);
    insert into t1_2 values(1, 2, 200);
    commit;
    analyze table t1_1 compute statistics;
    analyze table t1_2 compute statistics;
    prompt
    prompt #######################################
    prompt try 1 - works fine
    prompt #######################################
    prompt
    select * from t1
    where
    (c1=1)
    and
    ( (c2=2) and (c3=100)
    prompt
    prompt #######################################
    prompt try 2 - works fine
    prompt #######################################
    prompt
    select * from t1
    where
    (c1=1)
    and
    (c2=2) and (c3=200)
    prompt
    prompt #######################################
    prompt try 3 - try 1 OR try 2 does not work !
    prompt #######################################
    prompt
    select * from t1
    where
    (c1=1)
    and
    ( ( (c2=2) and (c3=100) )
    or
    ( (c2=2) and (c3=200) )
    opened a TAR and wanted to share with you.
    Tal Olier ([email protected]).

    Hi,
    The following test case is supplied in the metalink in bug no. 2871341, the base bug for this bug is 2679062.
    REPRODUCIBILITY:
    Reproduces constantly with simple test case below:
    TEST CASE:
    DROP TABLE A1
    CREATE TABLE A1 (X1 VARCHAR2(10), X2 VARCHAR2(10))
    REM *********** Create the second table: ***************
    DROP TABLE A2
    CREATE TABLE A2 (X1 VARCHAR2(10), X2 VARCHAR2(10))
    INSERT INTO A1 VALUES ('1','2');
    INSERT INTO A2 VALUES ('3','4');
    COMMIT;
    CREATE INDEX A1_X1 ON A1(X1 );
    CREATE INDEX A1_X2 ON A1(X2);
    CREATE INDEX A2_X1 ON A2(X1);
    CREATE INDEX A2_X2 ON A2(X2);
    CREATE OR REPLACE VIEW A_ALL AS SELECT * FROM A1 UNION ALL SELECT * FROM A2;
    ANALYZE TABLE A1 COMPUTE STATISTICS;
    ANALYZE TABLE A2 COMPUTE STATISTICS;
    SELECT * FROM A_ALL;
    SELECT * FROM A_ALL WHERE (X1='1' AND X2='2') ;
    SELECT * FROM A_ALL WHERE ((X1='1' AND X2='2') OR (X1='3' AND X2='4'));
    The 2nd query returns answer while the second is not !
    The following is published in the 9.2.0.4 fixed bug list:
    " 9204 - 2679062 - Wrong results possible from multi-column INLIST "
    I have installed 9.2.0.4 patch set on a win 2000 machine Oracle and saw that the above case is actually solved but our application which has a very similar case doesn't.
    After investigating I found the following test case that fails, it reproduces only when you have index on all columns (covering index):
    drop table t1_1;
    drop table t1_2;
    create table t1_1(c1 number, c2 number, c3 number);
    create table t1_2(c1 number, c2 number, c3 number);
    create index t1_1_ix on t1_1(c1, c2, c3);
    create index t1_2_ix on t1_2(c1, c2, c3);
    create or replace view t1 as select * from t1_1 union all select * from t1_2;
    insert into t1_1 values(1, 2, 100);
    insert into t1_2 values(1, 2, 200);
    commit;
    analyze table t1_1 compute statistics;
    analyze table t1_2 compute statistics;
    prompt
    prompt #######################################
    prompt try 1 - works fine
    prompt #######################################
    prompt
    select * from t1
    where
    (c1=1)
    and
    ( (c2=2) and (c3=100)
    prompt
    prompt #######################################
    prompt try 2 - works fine
    prompt #######################################
    prompt
    select * from t1
    where
    (c1=1)
    and
    (c2=2) and (c3=200)
    prompt
    prompt #######################################
    prompt try 3 - try 1 OR try 2 does not work !
    prompt #######################################
    prompt
    select * from t1
    where
    (c1=1)
    and
    ( ( (c2=2) and (c3=100) )
    or
    ( (c2=2) and (c3=200) )
    opened a TAR and wanted to share with you.
    Tal Olier ([email protected]).

  • Materialised view runs for ever ...

    Hi
    I'd appreciate if someone could shine some light on an issue I'm having with a materialised view.
    I inherited this when I came into my current project, so before you ask me why tables are not partitioned or why a MV is being used for such a scenario, the answer is I don't know!!
    Anyway ... I'm using "Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod" running on SUSE ...
    There are a number of normalised tables two of which contain in the region of 400million rows each and tend to grow at the rate of 27000 rows per day.
    There's a materialised view (for the purposes of providing fast interactive reporting) that is setup as a normal join between 4 tables; the above two and the other two are just basic dictionary type lookups each containing around 100 or so rows.
    SELECT .... FROM LargeTable1, LargeTable2, Lookup3, Lookup4 WHERE Lookup3.ID=LargeTable1.LID and LargeTable2.ID=LargeTable1.ID and LargeTable2.LID=Lookup4.ID ;
    Running a FULL refresh on the MV failes with a 'ora-01555 snapshot too old' error after about 5 days!! Then takes around the same amount of time to rollback. Can't do a FAST refresh, I think because logs and/or mv indecies are out of sync.
    Table space is 63% full and undo space is set to auto-extend.
    I've tried /*+RULE */ but that doesn't seem to make a huge difference.
    Why does it take so long? Why does it fail? What can I do to speed it up?
    Thanks in advance for your assistance.
    Edited by: 883758 on Sep 7, 2011 2:16 PM

    You should approach this as a SQL tuning exercise, without the ability to change the query itself.
    Are table statistics up to date? Look at the execution plan – does it look reasonable for you? Are there any indexes that can help? (I am thinking covering indexes on the large tables …)
    Iordan Iotzov
    http://iiotzov.wordpress.com/

  • Multiple cluster

    Can it be feasible to use multiple cluster can be implemented in Index view ?

    You can only have one clustered index on each SQL Server table, however there are two ways to create pseudo clustered indexes on a table:
    1.Create clustered indexed on a view (indexed view) that covers the table
    2.Create covering index on the entire table
    Let's look at the following table:
    CREATE TABLE t1
    c1 int,
    c2 varchar(5),
    c3 bigint,
    c4 datetime,
    CONSTRAINT PK_t1 PRIMARY KEY CLUSTERED (c1, c2, c3, c4)
    GO
    For option 1 above, here's the indexed view and clustered index:
    SET NUMERIC_ROUNDABORT OFF;
    SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT,
    QUOTED_IDENTIFIER, ANSI_NULLS ON;
    GO
    CREATE VIEW v1 WITH SCHEMABINDING
    AS
    SELECT c1, c2, c3, c4 FROM dbo.t1
    GO
    CREATE UNIQUE CLUSTERED INDEX cidx_v1 ON dbo.v1(c2, c3, c4, c1)
    GO
    For option 2 above, here’s the covering index:
    CREATE INDEX idx_PseudoClust ON t1(c3, c4) INCLUDE (c2, c1)
    GO
    So why would you want to do this? I'm sure that there are some very good reasons, but I've never had the need to do it. I recently had the discussion with a Microsoft engineer and thought it was interesting enough to share.
    Ref.
    http://weblogs.sqlteam.com/tarad/archive/2009/11/09/Multiple-ldquoclusteredrdquo-indexes-on-a-SQL-Server-table.aspx
    Ahsan Kabir Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread. http://www.aktechforum.blogspot.com/

  • Join SQL Statement

    Hello all,
    Good day.
    I've one question on how to create the optimal index to support the below JOIN statement.
    SELECT *      
    FROM
         "TABLE1" T_1 INNER JOIN "TABLE2" T_2
         ON T_1.FIELD_JOIN1 = T_2. FIELD_JOIN1 AND
         ON T_1.FIELD_JOIN2 = T_2. FIELD_JOIN2
    WHERE
         T_1.FIELD_WHERE3 and T_1. FIELD_WHERE4 and T_2. FIELD_WHERE5 and T_2. FIELD_WHERE6
    I noticed that in many cases, there will be 2 indexes are created on each table: one index to support the fields in JOIN Condition and the other to support the WHERE Clause.
    My initial thought is to combine the fields in the WHERE clause and JOIN Condition into one secondary index in order to make the index a 'covering index'.
    My proposed indexes:
    Index on TABLE1: MANDT, FIELD_WHERE3, FIELD_WHERE4, FIELD_JOIN1, FIELD_JOIN2
    Index on TABLE2: MANDT, FIELD_WHERE5, FIELD_WHERE6, FIELD_JOIN1, FIELD_JOIN2
    Let say all the fields in the JOIN Condition and WHERE Clause are very selective, is this recommended if we
    1) Create an index which contains the fields for both JOIN condition and WHERE clause?
    2) and the fields of the index will follow the above sequence, meaning the fields in WHERE clause are located at the beginning of the index?
    Thanks,
    KP

    Hi Volker, Hi Harald,
    Thanks for your reply.
    I wrote one SQL statement and tested it in ST05 and the execution plan is as follow.
    - how many rows in MSEG: 36,000,000 
    - how many rows on WHERE MSEG: 4,000  << Smaller
    - how many rows in MKPF: 5,700,000 
    - how many rows on WHERE MKPF: 3,200,000
    --> No of entries after joining the above tables plus the 'where' selection: 62 records
    SELECT
    FROM
      "MKPF" T_00
          INNER JOIN "MSEG" T_01
                ON T_01 . "MANDT" = '100' AND
                       T_00 . "MANDT" = T_01 . "MANDT" AND
                       T_00 . "MBLNR" = T_01 . "MBLNR" AND
                       T_00 . "MJAHR" = T_01 . "MJAHR"                           
    WHERE
          T_00 . "MANDT" = '100' AND
          T_01 . "MATNR" = '000000111216070006' AND
          T_01 . "WERKS" = '1201' AND 
          T_00 . "BUDAT" >= '20090401'
    From the execution plan above, the Outer table is MSEG and Nested Loop Join method is being used. I think correct access plan is used as only 62 records returned.
    SELECT STATEMENT ( Estimated Costs = 19 , Estimated #Rows = 182 )
    5 NESTED LOOPS
              ( Estim. Costs = 19 , Estim. #Rows = 182 )
                Estim. CPU-Costs = 1,646,549 Estim. IO-Costs = 19
    2 TABLE ACCESS BY INDEX ROWID MSEG
                  ( Estim. Costs = 18 , Estim. #Rows = 363 )
                  Estim. CPU-Costs = 412,866 Estim. IO-Costs = 18
    1 INDEX RANGE SCAN MSEG~M
    ( Estim. Costs = 1 , Estim. #Rows = 363 )
    Search Columns: 3
    Estim. CPU-Costs = 23,106 Estim. IO-Costs = 1
    Access Predicates
    4 TABLE ACCESS BY INDEX ROWID MKPF
    Estim. CPU-Costs = 3,399 Estim. IO-Costs = 0
    Filter Predicates
    3 INDEX RANGE Scan MKPF~3
    I think there is a room to further improve the above statement by
    1) Append the fields in the JOIN condition to the index MSEG~M, so the field sequence of this index would be
         MANDT, MATNR , WERKS, MBLNR, MJAHR 
    2) Append the fields (BUDAT) in the WHERE condition to the index MSEG~M, so the field sequence of this index would be
         MANDT, BUDAT, MBLNR, MJAHR      (The distinct number of field BUDAT is 840)
         --> I doubt that whether to put BUDAT at the beginning of the index because operator GE ">=" is used with BUDAT. Do you have any comment on this?
    3) Let's assume BUDAT is used with Equal operator "=", will this field sequence look fine?
        MANDT, BUDAT, MBLNR, MJAHR
    Your comments will be much appreciated. Thank you.
    Best regards,
    KP

  • Very Bad performance with high stress on Tempdb

    Hello ,
    below is the execution plan for a query rapidly increase the Tempdb and has very slow performance,
    appreciate your suggestion to enhance this query (any data is available upon request) 

    >Covering indexes will make a huge difference.
    You can't simply "create-covering-index" yourself out from every performance jam.
    Questions:
    Is the query important enough to justify special consideration?
    How many covering indexes?
    What is the performance impact of the new covering indexes on other queries?
    Query optimization:
    http://www.sqlusa.com/articles/query-optimization/
    Kalman Toth Database & OLAP Architect
    SELECT Video Tutorials 4 Hours
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Wrong cover art

    Some cover art is wrong on my iPod - it picked up another CD's cover and applied it to several other CDs. How can I correct them?

    Try these sites:
    http://www.slothradio.com/covers/index.php
    http://albumart.org/
    Step 1. Find the album art you are looking for.
    Step 2. Save the image to your computer.
    Step 3. Open iTunes. (If it isn't already open.)
    Step 4. Highlight the songs you want to tag with the album art.
    Step 5. With the songs highlighted, right-click and choose "Get Info."
    Step 6. Find the image you saved to your computer. Copy the image.
    Step 7. In iTunes, with the "Get Info" box open, paste the image into the "Artwork" box.
    Step 8. Click "OK."
    Step 9. Sync your iPod. The correct Artwork should now appear on your songs.

  • Long time creating execution plan on wide table

    When executing a select on a wide table, with a column set and sparse columns, it always takes 12 seconds or longer to create the execution plan, even on an empty
    table. We used the database option ‘SET
    PARAMETERIZATION FORCED’ but it does not resolve the issue. We also tried ‘INDEXED
    VIEWS’ and ‘FILTERED INDEXES’
    without success. A covering index resolves the problem but this cannot be implemented as a general solution. We tested this on SQL Server 2008, 2008 R8, 2012 and 2014.
    The following queries (with their actual execution plans included in picture) all experience the problem:
    SELECT
    TOP (1)
      [ISN], [TIMESTAMP], [FIRMEN_NR], [SATZART], [TAB_SPERR_KZ],
    [DATUM_AEND], [UHRZEIT_AEND], [LFDNR],
      [BEARBEITER], [STEUERUNG], [UMSATZSCHLUESSEL], [US_W_S_KZ],
    [US_G_L_KZ], [VL_KZ], [RABATT_KZ],
      [INPUT_KZ], [ZAST_PFLICHTIGER_US], [BEWEG_SCHL1_1], [BEWEG_SCHL1_2],
    [BEWEG_SCHL1_3], [BEWEG_SCHL1_4],
    [BEWEG_SCHL1_5], [BEWEG_SCHL2_1], [BEWEG_SCHL2_2], [BEWEG_SCHL2_3], [BEWEG_SCHL2_4],
    [BEWEG_SCHL2_5],
      [WERT_KZ_1], [WERT_KZ_2], [WERT_KZ_3], [WERT_KZ_4], [WERT_KZ_5],
    [PREIS_KZ_1], [PREIS_KZ_2], [PREIS_KZ_3],
      [PREIS_KZ_4], [PREIS_KZ_5], [US_BEZ_1],
    [US_BEZ_2], [US_BEZ_3], [US_BEZ2_1], [US_BEZ2_2], [US_BEZ2_3],
      [GEGEN_KONTO], [EIN_AUSZAHLUNGS_KZ], [ABR_DRUCK_KZ], [UPFRONT_FEE],
    [LARG]
    FROM [IAM800_A]
    WHERE [IAM880_KEY1_N3]
    = 0x3033383830303532
    ORDER
    BY [ISN] ASC
    SELECT
    -- now without TOP (1)
      [ISN], [TIMESTAMP], [FIRMEN_NR], [SATZART], [TAB_SPERR_KZ],
    [DATUM_AEND], [UHRZEIT_AEND], [LFDNR],
      [BEARBEITER], [STEUERUNG], [UMSATZSCHLUESSEL], [US_W_S_KZ],
    [US_G_L_KZ], [VL_KZ], [RABATT_KZ],
      [INPUT_KZ], [ZAST_PFLICHTIGER_US], [BEWEG_SCHL1_1], [BEWEG_SCHL1_2],
    [BEWEG_SCHL1_3], [BEWEG_SCHL1_4],
    [BEWEG_SCHL1_5], [BEWEG_SCHL2_1], [BEWEG_SCHL2_2], [BEWEG_SCHL2_3], [BEWEG_SCHL2_4],
    [BEWEG_SCHL2_5],
      [WERT_KZ_1], [WERT_KZ_2], [WERT_KZ_3], [WERT_KZ_4], [WERT_KZ_5],
    [PREIS_KZ_1], [PREIS_KZ_2], [PREIS_KZ_3],
      [PREIS_KZ_4], [PREIS_KZ_5], [US_BEZ_1],
    [US_BEZ_2], [US_BEZ_3], [US_BEZ2_1], [US_BEZ2_2], [US_BEZ2_3],
      [GEGEN_KONTO], [EIN_AUSZAHLUNGS_KZ], [ABR_DRUCK_KZ], [UPFRONT_FEE],
    [LARG]
    FROM [IAM800_A]
    WHERE [IAM880_KEY1_N3]
    = 0x3033383830303532
    ORDER
    BY [ISN] ASC
    SELECT [ISN], [FIRMEN_NR]
    FROM [IAM800_A]
    WHERE [IAM880_KEY1_N3]
    = 0x3033383830303532
    ORDER
    BY [ISN] ASC
    Execution plans for above queries:

    Sorry my mistake. As these definitions fit within the size of a reply, I am posting them directly.
    Do note the use of a filegroup.
    PRINT 'Adding indexes to table [dbo].[IAM800_A]...'
    GO
    SET ANSI_NULLS              ON
    SET ANSI_PADDING            ON
    SET ANSI_WARNINGS           ON
    SET ARITHABORT              ON
    SET CONCAT_NULL_YIELDS_NULL ON
    SET NUMERIC_ROUNDABORT      OFF
    SET QUOTED_IDENTIFIER       ON
    GO
    -- Primary Key (ISN)
    ALTER TABLE [dbo].[IAM800_A] ADD CONSTRAINT [IAM800_A:ISN]
      PRIMARY KEY CLUSTERED ( [ISN] )
      ON [FG001_Data]
    GO
    -- Non-Clustered Indexes (Descriptors)
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM505-KEY1]
      ON [dbo].[IAM800_A] ( [IAM505_KEY1], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM810-KEY1]
      ON [dbo].[IAM800_A] ( [IAM810_KEY1], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM820-KEY1]
      ON [dbo].[IAM800_A] ( [IAM820_KEY1], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM830-KEY1]
      ON [dbo].[IAM800_A] ( [IAM830_KEY1], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM835-KEY1]
      ON [dbo].[IAM800_A] ( [IAM835_KEY1], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM840-KEY1]
      ON [dbo].[IAM800_A] ( [IAM840_KEY1], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM841-KEY1-ALT]
      ON [dbo].[IAM800_A] ( [IAM841_KEY1_ALT], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM842-KEY1]
      ON [dbo].[IAM800_A] ( [IAM842_KEY1], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM843-KEY1]
      ON [dbo].[IAM800_A] ( [IAM843_KEY1], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM845-KEY1]
      ON [dbo].[IAM800_A] ( [IAM845_KEY1], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM850-KEY1]
      ON [dbo].[IAM800_A] ( [IAM850_KEY1], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM860-KEY1]
      ON [dbo].[IAM800_A] ( [IAM860_KEY1], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM870-KEY1]
      ON [dbo].[IAM800_A] ( [IAM870_KEY1], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM875-KEY1]
      ON [dbo].[IAM800_A] ( [IAM875_KEY1], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM880-KEY1-N3]
      ON [dbo].[IAM800_A] ( [IAM880_KEY1_N3], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM885-KEY1]
      ON [dbo].[IAM800_A] ( [IAM885_KEY1], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM899-KEY1]
      ON [dbo].[IAM800_A] ( [IAM899_KEY1], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM899-KEY2]
      ON [dbo].[IAM800_A] ( [IAM899_KEY2], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM899-KEY3]
      ON [dbo].[IAM800_A] ( [IAM899_KEY3], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM800-KEY1]
      ON [dbo].[IAM800_A] ( [IAM800_KEY1], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM841-KEY1]
      ON [dbo].[IAM800_A] ( [IAM841_KEY1], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM886-KEY1]
      ON [dbo].[IAM800_A] ( [IAM886_KEY1], [ISN] )
      ON [FG002_Index]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IAM800_A:SUPER-DESCRIPTOR:IAM876-KEY1]
      ON [dbo].[IAM800_A] ( [IAM876_KEY1], [ISN] )
      ON [FG002_Index]
    GO

  • Specialist Database

    Hi, 
    I am facing issue of deadlock and exclusive locks on some of tables for Hybris application. Using MSSQL 2008 R2 standard edition.
    Case is Update hits database and take X lock on val1 record and goes in sleeping mode. When update is in sleeping mode and lock is not release, during that all select comes to that table get suspended. That is creating some deadlock or intensive blocking
    in database. 
    As of now i have applied following solutions: 
    - Covering index has been introduced for some of columns in select
    - Updated STATS for tables in scope of UPDATE and SELECT 
    - Rebuilt indexes on regular basis 
    But problem frequency is reduced but not permanently resolved. Any help appreciated here.. 

    http://blogs.msdn.com/bartd/archive/2006/09/09/747119.aspx
    http://blogs.msdn.com/bartd/archive/2006/09/25/770928.aspx
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Function-based index with OR in the wher-clause

    We have some problems with functin-based indexes and
    the or-condition in a where-clause.
    --We use Oracle 8i (8.1.7)
    create table TPERSON(ID number(10),NAME varchar2(20),...);
    create index I_NORMAL_TPERSON_NAME on TPERSON(NAME);
    create index I_FUNCTION_TPERSON_NAME on TPERSON(UPPER(NAME));
    The following two statements run very fast on a large table
    and the execution-plan asure the usage of the indexes
    (-while the session is appropriate configured and the table is analyzed):
    1)     select count(ID) FROM TPERSON where upper(NAME) like 'MIL%';
    2)     select count(ID) from TPERSON where NAME like 'Mil%' or (3=5);
    In particular we see that a normal index is used while the where-clause contains
    an OR-CONDITION.
    But if we try the similarly select-statement
    3)     select count(ID) FROM TPERSON where upper(NAME) like 'MIL%' or (3=5);
    the CBO will not use the function-index I_FUNCTION_TPERSON_NAME and we have a full table scan in the execution-plan.
    (This behavior we only expect with views but not with indexes.)
    We ask for an advice like a hint, which enable the CBO-usage
    of function-based indexes in connection with OR.
    This problem seems to be artificial because it contains this dummy logic:
         or (3=5).
    This steams from an prepared statement, where this kind of boolean
    flag reduce the amount of different select-statements needed for
    covering the hole business-logic, while using bind-variables for the
    concrete query-parameters.
    A more realistic (still boild down) version of our select-statement is:
    select * FROM TPERSON
    where (upper(NAME) like 'MIL%' or (NAME is null))
    and (upper(FIRSTNAME) like 'MICH% or (FIRSTNAME is null))
    and ...;
    thank you for time..
    email: [email protected]

    In the realistic statement you write :
    select * FROM TPERSON
    where (upper(NAME) like 'MIL%' or (NAME is null))
    and (upper(FIRSTNAME) like 'MICH% or (FIRSTNAME is null))
    and ...;
    as far as i know, NULL values are not indexed, "or (NAME is NULL)" have to generate a full table scan.
    HTH
    We have some problems with functin-based indexes and
    the or-condition in a where-clause.
    --We use Oracle 8i (8.1.7)
    create table TPERSON(ID number(10),NAME varchar2(20),...);
    create index I_NORMAL_TPERSON_NAME on TPERSON(NAME);
    create index I_FUNCTION_TPERSON_NAME on TPERSON(UPPER(NAME));
    The following two statements run very fast on a large table
    and the execution-plan asure the usage of the indexes
    (-while the session is appropriate configured and the table is analyzed):
    1)     select count(ID) FROM TPERSON where upper(NAME) like 'MIL%';
    2)     select count(ID) from TPERSON where NAME like 'Mil%' or (3=5);
    In particular we see that a normal index is used while the where-clause contains
    an OR-CONDITION.
    But if we try the similarly select-statement
    3)     select count(ID) FROM TPERSON where upper(NAME) like 'MIL%' or (3=5);
    the CBO will not use the function-index I_FUNCTION_TPERSON_NAME and we have a full table scan in the execution-plan.
    (This behavior we only expect with views but not with indexes.)
    We ask for an advice like a hint, which enable the CBO-usage
    of function-based indexes in connection with OR.
    This problem seems to be artificial because it contains this dummy logic:
         or (3=5).
    This steams from an prepared statement, where this kind of boolean
    flag reduce the amount of different select-statements needed for
    covering the hole business-logic, while using bind-variables for the
    concrete query-parameters.
    A more realistic (still boild down) version of our select-statement is:
    select * FROM TPERSON
    where (upper(NAME) like 'MIL%' or (NAME is null))
    and (upper(FIRSTNAME) like 'MICH% or (FIRSTNAME is null))
    and ...;
    thank you for time..
    email: [email protected]

Maybe you are looking for

  • PNG files no longer display correctly...PLEASE HELP!

    Hi there, I just recently upgraded to Final Cut Studio 2. I have a project that I was working on prior to the upgrade and now making some changes in DVD Studio Pro 4.2.0. In my menus I am using a motion menu as the background and a PNG file created i

  • Billed for movie I've not yet watched

    Sorry if this has been asked before, tried a search but difficult to choose appropriate keywords. Anyway... When does iTunes bill you for renting a movie? As soon as you start downloading it or only if you press "play" & begin the 24 hour rental peri

  • GRC Access Control 5.3 CUP Role Provisioning Approval Buttons Missing

    When Approvers receive a Request in Compliant User Provisioning via email they click on the link but the action buttons are missing. (example approval, reject approval buttons are missing).  When they log in through the lauch pad the action buttons a

  • Help w/ E-mail and Director

    Hey all. I need to find code for Director to access G-Mail. I want to be able to recieve and send mail. And then take those e-mails and take information from them and use it in the shockwave file. Is there anyway I can do this?

  • I have an Intel-based iMac G5, running OS 10.6.8. Can I upgrade to Mountain Lion?

    I just upgraded from 2GB RAM to 4GB, thinking this was all I needed to do. But now it's telling me that Mountain Lion won't run on my machine. So am I stuck in the pre-iCloud world?