Indexing strategy for a query involving three views, multiple columns and several JOINs
The scenario
I am having issues with a SELECT query on a view named V3, which takes ages (I had to cancel in SSMS, it timeouts in the application). V3 combines two other views, V1 and V2, to get a one-row result in the end (WHERE clause with idx value).
V3 is defined the following way:
SELECT Live_DataIdx, DTLive1, DTLive2, DTLive3, DTLive4, DTDelivery, DTData2, DTLive5, DTData3, DTData4, Desc, Counter, DataFormat, DataType, Live_QueueIdx, Live_QueueGUID
FROM V1
UNION
SELECT History_DataIdx, DTLive1, DTLive2, DTLive3, DTLive4, DTDelivery, DTData2, DTLive5, DTData3, DTData4, Desc, Counter, DataFormat, DataType, live_QueueIdx, Live_QueueGUID
FROM V2
V1 definition:
SELECT DISTINCT TOP (100) PERCENT dbo.Live_Data.Live_DataIdx,dbo.Live_Queue.DTLive1,dbo.Live_Queue.DTLive2, dbo.Live_Queue.DTLive3,dbo.Live_Queue.DTLive4, dbo.Live_Data.DTData1 AS DTDelivery,dbo.Live_Data.DTData2, dbo.Live_Queue.DTLive5,dbo.Live_Data.DTData3,dbo.Live_Data.DTData4, dbo.MsgType.Desc, dbo.Live_Data.Counter, dbo.Live_Queue.DataFormat, dbo.Live_Data.DataType, dbo.Live_Queue.Live_QueueIdx, dbo.Live_Queue.Live_QueueGUID
FROM dbo.Data
INNER JOIN dbo.Live_Data ON dbo.Data.DataGUID = dbo.Live_Data.DataGUID
INNER JOIN dbo.MsgType ON dbo.Live_Data.MsgTypeGUID = dbo.MsgType.MsgTypeGUID
LEFT OUTER JOIN dbo.Live_Queue ON dbo.Live_Data.Live_QueueGUID = dbo.Live_Queue.Live_QueueGUID
ORDER BY dbo.Live_Data.Live_DataIdx DESC
V2 is declared as follows:
SELECT DISTINCT TOP (100) PERCENT dbo.History_Data.History_DataIdx, dbo.History_Queue.DTLive1, dbo.History_Queue.DTLive2, dbo.History_Queue.DTLive3,
dbo.History_Queue.DTLive4, dbo.History_Data.DTData1 AS DTDelivery, dbo.History_Data.DTData2, dbo.History_Queue.DTLive5,
dbo.History_Data.DTData3, dbo.History_Data.DTData4, dbo.MsgType.Desc, dbo.History_Data.Counter, dbo.History_Queue.DataFormat, dbo.History_Data.DataType,
dbo.History_Queue.History_QueueIdx AS live_QueueIdx, dbo.History_Queue.Live_QueueGUID
FROM dbo.Data
INNER JOIN dbo.History_Data ON dbo.Data.DataGUID = dbo.History_Data.DataGUID
INNER JOIN dbo.MsgType ON dbo.History_Data.MsgTypeGUID = dbo.MsgType.MsgTypeGUID
LEFT OUTER JOIN dbo.History_Queue ON dbo.History_Data.Live_QueueGUID = dbo.History_Queue.Live_QueueGUID
ORDER BY dbo.History_Data.History_DataIdx DESC
I am calling view V3 via Linq2SQL (but I did also try in SSMS) with the following query:
SELECT [Desc],Counter,DataType,DataFormat,DTLive1,DTData3,DTData4,
DTDelivery,DTData2,DTLive2,DTLive3,DTLive5,DTLive4
FROM V3
WHERE Live_QueueIdx = 4325324
My request
Thus, I am asking for hints about creating some indices (if recommended: how should those be structed) or reconsiderations about the query. I don't think this use-case is of anything unique, so there has to be plans outside for this kind of a query.
Considerations
These views are just overwhelming to start digging into the solution of the right index composition. I did already try some nonclustered indices, but I am not sure about it, because the query just don't stop (waiting for more than 10 minutes), my feeling is that there's some other problem. The NCIs also didn't have any effect. Many different factors need to be considered:
- Multiple columns are requested. Which column set might be responsible for the delay? Only one, many, all but one?
- Multiple joins do exist
- Where clause is used on an idx value
The problem lies within V2 that contains the history data (~1.5 million entries in each history table), V1 can be called in an instance. But because V3 is an UNION of both, V3 suffers from the slowmotion effect of V2. The idea behind the V3 is to combine live and history data to get one specific entry with the selected idx value (here: 4325324) in the end.
The V1 and V2 views are nearly equal, the only difference is that V2 is built with the history tables (History_Data and History_Queue) instead of the live tables (Live_Data and Live_Queue), while both have the same structure.
Any of the tables above has a primary key on a uniqueidentifier value (see listing below), thus automatically a clustered index on it:
Data:DataGuid
Live_Data:Live_DataGUID
MsgType:MsgTypeGUID
Live_Queue:Live_QueueGUID
History_Data:Live_DataGUID
History_Queue:Live_QueueGUID
The select query runs like endlessly, I stopped after a period of more than 10 minutes.
Execution plan
The execution plan can be regarded at the following PasteThePlan URI: Estimated Execution Plan
Note: I removed the nonclustered indices. I tried to add to start from the beginning again to get an idea how to begin systematically on this kind of slowmotion issues.
Any help is kindly appreciated, not only indexwise, but conceptually, too. Thank you.
sql-server index optimization
New contributor
kvirk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
|
show 7 more comments
The scenario
I am having issues with a SELECT query on a view named V3, which takes ages (I had to cancel in SSMS, it timeouts in the application). V3 combines two other views, V1 and V2, to get a one-row result in the end (WHERE clause with idx value).
V3 is defined the following way:
SELECT Live_DataIdx, DTLive1, DTLive2, DTLive3, DTLive4, DTDelivery, DTData2, DTLive5, DTData3, DTData4, Desc, Counter, DataFormat, DataType, Live_QueueIdx, Live_QueueGUID
FROM V1
UNION
SELECT History_DataIdx, DTLive1, DTLive2, DTLive3, DTLive4, DTDelivery, DTData2, DTLive5, DTData3, DTData4, Desc, Counter, DataFormat, DataType, live_QueueIdx, Live_QueueGUID
FROM V2
V1 definition:
SELECT DISTINCT TOP (100) PERCENT dbo.Live_Data.Live_DataIdx,dbo.Live_Queue.DTLive1,dbo.Live_Queue.DTLive2, dbo.Live_Queue.DTLive3,dbo.Live_Queue.DTLive4, dbo.Live_Data.DTData1 AS DTDelivery,dbo.Live_Data.DTData2, dbo.Live_Queue.DTLive5,dbo.Live_Data.DTData3,dbo.Live_Data.DTData4, dbo.MsgType.Desc, dbo.Live_Data.Counter, dbo.Live_Queue.DataFormat, dbo.Live_Data.DataType, dbo.Live_Queue.Live_QueueIdx, dbo.Live_Queue.Live_QueueGUID
FROM dbo.Data
INNER JOIN dbo.Live_Data ON dbo.Data.DataGUID = dbo.Live_Data.DataGUID
INNER JOIN dbo.MsgType ON dbo.Live_Data.MsgTypeGUID = dbo.MsgType.MsgTypeGUID
LEFT OUTER JOIN dbo.Live_Queue ON dbo.Live_Data.Live_QueueGUID = dbo.Live_Queue.Live_QueueGUID
ORDER BY dbo.Live_Data.Live_DataIdx DESC
V2 is declared as follows:
SELECT DISTINCT TOP (100) PERCENT dbo.History_Data.History_DataIdx, dbo.History_Queue.DTLive1, dbo.History_Queue.DTLive2, dbo.History_Queue.DTLive3,
dbo.History_Queue.DTLive4, dbo.History_Data.DTData1 AS DTDelivery, dbo.History_Data.DTData2, dbo.History_Queue.DTLive5,
dbo.History_Data.DTData3, dbo.History_Data.DTData4, dbo.MsgType.Desc, dbo.History_Data.Counter, dbo.History_Queue.DataFormat, dbo.History_Data.DataType,
dbo.History_Queue.History_QueueIdx AS live_QueueIdx, dbo.History_Queue.Live_QueueGUID
FROM dbo.Data
INNER JOIN dbo.History_Data ON dbo.Data.DataGUID = dbo.History_Data.DataGUID
INNER JOIN dbo.MsgType ON dbo.History_Data.MsgTypeGUID = dbo.MsgType.MsgTypeGUID
LEFT OUTER JOIN dbo.History_Queue ON dbo.History_Data.Live_QueueGUID = dbo.History_Queue.Live_QueueGUID
ORDER BY dbo.History_Data.History_DataIdx DESC
I am calling view V3 via Linq2SQL (but I did also try in SSMS) with the following query:
SELECT [Desc],Counter,DataType,DataFormat,DTLive1,DTData3,DTData4,
DTDelivery,DTData2,DTLive2,DTLive3,DTLive5,DTLive4
FROM V3
WHERE Live_QueueIdx = 4325324
My request
Thus, I am asking for hints about creating some indices (if recommended: how should those be structed) or reconsiderations about the query. I don't think this use-case is of anything unique, so there has to be plans outside for this kind of a query.
Considerations
These views are just overwhelming to start digging into the solution of the right index composition. I did already try some nonclustered indices, but I am not sure about it, because the query just don't stop (waiting for more than 10 minutes), my feeling is that there's some other problem. The NCIs also didn't have any effect. Many different factors need to be considered:
- Multiple columns are requested. Which column set might be responsible for the delay? Only one, many, all but one?
- Multiple joins do exist
- Where clause is used on an idx value
The problem lies within V2 that contains the history data (~1.5 million entries in each history table), V1 can be called in an instance. But because V3 is an UNION of both, V3 suffers from the slowmotion effect of V2. The idea behind the V3 is to combine live and history data to get one specific entry with the selected idx value (here: 4325324) in the end.
The V1 and V2 views are nearly equal, the only difference is that V2 is built with the history tables (History_Data and History_Queue) instead of the live tables (Live_Data and Live_Queue), while both have the same structure.
Any of the tables above has a primary key on a uniqueidentifier value (see listing below), thus automatically a clustered index on it:
Data:DataGuid
Live_Data:Live_DataGUID
MsgType:MsgTypeGUID
Live_Queue:Live_QueueGUID
History_Data:Live_DataGUID
History_Queue:Live_QueueGUID
The select query runs like endlessly, I stopped after a period of more than 10 minutes.
Execution plan
The execution plan can be regarded at the following PasteThePlan URI: Estimated Execution Plan
Note: I removed the nonclustered indices. I tried to add to start from the beginning again to get an idea how to begin systematically on this kind of slowmotion issues.
Any help is kindly appreciated, not only indexwise, but conceptually, too. Thank you.
sql-server index optimization
New contributor
kvirk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
How many records do you expect to get as a result?
– Akina
yesterday
The query above may return 500000-1500000 rows, although in the end, I do only need one row, specified by the idx value on V3 like SELECT A.Col1,B.Col1,C.Col1,A.Col2,B.Col2,A.Col3,B.Col3,C.Col3,A.Col4,A.Col5, D.Col1 FROM V3 WHERE idx = 4325324, with idx being a column of one of the tables of the query above.
– kvirk
yesterday
1
Insert this condition (WHERE idx = 4325324) by adding V3 view into your query source (FROM section or CTE)
– Akina
yesterday
1
SELECT * FROM V1 WHERE idx = 4325324 UNION SELECT * FROM V2 WHERE idx = 4325324. I hope the server is smart enough to insert the condition into subqueries and execute as the condition is in view text. PS. There is noidxfield in your view source text...
– Akina
yesterday
1
I would recommend defining yourv3view using the specific columns required from thev1andv2views. Using the potent*(asterisk) to select all column has the potential to break things should the viewsv1andv2change in the future.
– hot2use
15 hours ago
|
show 7 more comments
The scenario
I am having issues with a SELECT query on a view named V3, which takes ages (I had to cancel in SSMS, it timeouts in the application). V3 combines two other views, V1 and V2, to get a one-row result in the end (WHERE clause with idx value).
V3 is defined the following way:
SELECT Live_DataIdx, DTLive1, DTLive2, DTLive3, DTLive4, DTDelivery, DTData2, DTLive5, DTData3, DTData4, Desc, Counter, DataFormat, DataType, Live_QueueIdx, Live_QueueGUID
FROM V1
UNION
SELECT History_DataIdx, DTLive1, DTLive2, DTLive3, DTLive4, DTDelivery, DTData2, DTLive5, DTData3, DTData4, Desc, Counter, DataFormat, DataType, live_QueueIdx, Live_QueueGUID
FROM V2
V1 definition:
SELECT DISTINCT TOP (100) PERCENT dbo.Live_Data.Live_DataIdx,dbo.Live_Queue.DTLive1,dbo.Live_Queue.DTLive2, dbo.Live_Queue.DTLive3,dbo.Live_Queue.DTLive4, dbo.Live_Data.DTData1 AS DTDelivery,dbo.Live_Data.DTData2, dbo.Live_Queue.DTLive5,dbo.Live_Data.DTData3,dbo.Live_Data.DTData4, dbo.MsgType.Desc, dbo.Live_Data.Counter, dbo.Live_Queue.DataFormat, dbo.Live_Data.DataType, dbo.Live_Queue.Live_QueueIdx, dbo.Live_Queue.Live_QueueGUID
FROM dbo.Data
INNER JOIN dbo.Live_Data ON dbo.Data.DataGUID = dbo.Live_Data.DataGUID
INNER JOIN dbo.MsgType ON dbo.Live_Data.MsgTypeGUID = dbo.MsgType.MsgTypeGUID
LEFT OUTER JOIN dbo.Live_Queue ON dbo.Live_Data.Live_QueueGUID = dbo.Live_Queue.Live_QueueGUID
ORDER BY dbo.Live_Data.Live_DataIdx DESC
V2 is declared as follows:
SELECT DISTINCT TOP (100) PERCENT dbo.History_Data.History_DataIdx, dbo.History_Queue.DTLive1, dbo.History_Queue.DTLive2, dbo.History_Queue.DTLive3,
dbo.History_Queue.DTLive4, dbo.History_Data.DTData1 AS DTDelivery, dbo.History_Data.DTData2, dbo.History_Queue.DTLive5,
dbo.History_Data.DTData3, dbo.History_Data.DTData4, dbo.MsgType.Desc, dbo.History_Data.Counter, dbo.History_Queue.DataFormat, dbo.History_Data.DataType,
dbo.History_Queue.History_QueueIdx AS live_QueueIdx, dbo.History_Queue.Live_QueueGUID
FROM dbo.Data
INNER JOIN dbo.History_Data ON dbo.Data.DataGUID = dbo.History_Data.DataGUID
INNER JOIN dbo.MsgType ON dbo.History_Data.MsgTypeGUID = dbo.MsgType.MsgTypeGUID
LEFT OUTER JOIN dbo.History_Queue ON dbo.History_Data.Live_QueueGUID = dbo.History_Queue.Live_QueueGUID
ORDER BY dbo.History_Data.History_DataIdx DESC
I am calling view V3 via Linq2SQL (but I did also try in SSMS) with the following query:
SELECT [Desc],Counter,DataType,DataFormat,DTLive1,DTData3,DTData4,
DTDelivery,DTData2,DTLive2,DTLive3,DTLive5,DTLive4
FROM V3
WHERE Live_QueueIdx = 4325324
My request
Thus, I am asking for hints about creating some indices (if recommended: how should those be structed) or reconsiderations about the query. I don't think this use-case is of anything unique, so there has to be plans outside for this kind of a query.
Considerations
These views are just overwhelming to start digging into the solution of the right index composition. I did already try some nonclustered indices, but I am not sure about it, because the query just don't stop (waiting for more than 10 minutes), my feeling is that there's some other problem. The NCIs also didn't have any effect. Many different factors need to be considered:
- Multiple columns are requested. Which column set might be responsible for the delay? Only one, many, all but one?
- Multiple joins do exist
- Where clause is used on an idx value
The problem lies within V2 that contains the history data (~1.5 million entries in each history table), V1 can be called in an instance. But because V3 is an UNION of both, V3 suffers from the slowmotion effect of V2. The idea behind the V3 is to combine live and history data to get one specific entry with the selected idx value (here: 4325324) in the end.
The V1 and V2 views are nearly equal, the only difference is that V2 is built with the history tables (History_Data and History_Queue) instead of the live tables (Live_Data and Live_Queue), while both have the same structure.
Any of the tables above has a primary key on a uniqueidentifier value (see listing below), thus automatically a clustered index on it:
Data:DataGuid
Live_Data:Live_DataGUID
MsgType:MsgTypeGUID
Live_Queue:Live_QueueGUID
History_Data:Live_DataGUID
History_Queue:Live_QueueGUID
The select query runs like endlessly, I stopped after a period of more than 10 minutes.
Execution plan
The execution plan can be regarded at the following PasteThePlan URI: Estimated Execution Plan
Note: I removed the nonclustered indices. I tried to add to start from the beginning again to get an idea how to begin systematically on this kind of slowmotion issues.
Any help is kindly appreciated, not only indexwise, but conceptually, too. Thank you.
sql-server index optimization
New contributor
kvirk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
The scenario
I am having issues with a SELECT query on a view named V3, which takes ages (I had to cancel in SSMS, it timeouts in the application). V3 combines two other views, V1 and V2, to get a one-row result in the end (WHERE clause with idx value).
V3 is defined the following way:
SELECT Live_DataIdx, DTLive1, DTLive2, DTLive3, DTLive4, DTDelivery, DTData2, DTLive5, DTData3, DTData4, Desc, Counter, DataFormat, DataType, Live_QueueIdx, Live_QueueGUID
FROM V1
UNION
SELECT History_DataIdx, DTLive1, DTLive2, DTLive3, DTLive4, DTDelivery, DTData2, DTLive5, DTData3, DTData4, Desc, Counter, DataFormat, DataType, live_QueueIdx, Live_QueueGUID
FROM V2
V1 definition:
SELECT DISTINCT TOP (100) PERCENT dbo.Live_Data.Live_DataIdx,dbo.Live_Queue.DTLive1,dbo.Live_Queue.DTLive2, dbo.Live_Queue.DTLive3,dbo.Live_Queue.DTLive4, dbo.Live_Data.DTData1 AS DTDelivery,dbo.Live_Data.DTData2, dbo.Live_Queue.DTLive5,dbo.Live_Data.DTData3,dbo.Live_Data.DTData4, dbo.MsgType.Desc, dbo.Live_Data.Counter, dbo.Live_Queue.DataFormat, dbo.Live_Data.DataType, dbo.Live_Queue.Live_QueueIdx, dbo.Live_Queue.Live_QueueGUID
FROM dbo.Data
INNER JOIN dbo.Live_Data ON dbo.Data.DataGUID = dbo.Live_Data.DataGUID
INNER JOIN dbo.MsgType ON dbo.Live_Data.MsgTypeGUID = dbo.MsgType.MsgTypeGUID
LEFT OUTER JOIN dbo.Live_Queue ON dbo.Live_Data.Live_QueueGUID = dbo.Live_Queue.Live_QueueGUID
ORDER BY dbo.Live_Data.Live_DataIdx DESC
V2 is declared as follows:
SELECT DISTINCT TOP (100) PERCENT dbo.History_Data.History_DataIdx, dbo.History_Queue.DTLive1, dbo.History_Queue.DTLive2, dbo.History_Queue.DTLive3,
dbo.History_Queue.DTLive4, dbo.History_Data.DTData1 AS DTDelivery, dbo.History_Data.DTData2, dbo.History_Queue.DTLive5,
dbo.History_Data.DTData3, dbo.History_Data.DTData4, dbo.MsgType.Desc, dbo.History_Data.Counter, dbo.History_Queue.DataFormat, dbo.History_Data.DataType,
dbo.History_Queue.History_QueueIdx AS live_QueueIdx, dbo.History_Queue.Live_QueueGUID
FROM dbo.Data
INNER JOIN dbo.History_Data ON dbo.Data.DataGUID = dbo.History_Data.DataGUID
INNER JOIN dbo.MsgType ON dbo.History_Data.MsgTypeGUID = dbo.MsgType.MsgTypeGUID
LEFT OUTER JOIN dbo.History_Queue ON dbo.History_Data.Live_QueueGUID = dbo.History_Queue.Live_QueueGUID
ORDER BY dbo.History_Data.History_DataIdx DESC
I am calling view V3 via Linq2SQL (but I did also try in SSMS) with the following query:
SELECT [Desc],Counter,DataType,DataFormat,DTLive1,DTData3,DTData4,
DTDelivery,DTData2,DTLive2,DTLive3,DTLive5,DTLive4
FROM V3
WHERE Live_QueueIdx = 4325324
My request
Thus, I am asking for hints about creating some indices (if recommended: how should those be structed) or reconsiderations about the query. I don't think this use-case is of anything unique, so there has to be plans outside for this kind of a query.
Considerations
These views are just overwhelming to start digging into the solution of the right index composition. I did already try some nonclustered indices, but I am not sure about it, because the query just don't stop (waiting for more than 10 minutes), my feeling is that there's some other problem. The NCIs also didn't have any effect. Many different factors need to be considered:
- Multiple columns are requested. Which column set might be responsible for the delay? Only one, many, all but one?
- Multiple joins do exist
- Where clause is used on an idx value
The problem lies within V2 that contains the history data (~1.5 million entries in each history table), V1 can be called in an instance. But because V3 is an UNION of both, V3 suffers from the slowmotion effect of V2. The idea behind the V3 is to combine live and history data to get one specific entry with the selected idx value (here: 4325324) in the end.
The V1 and V2 views are nearly equal, the only difference is that V2 is built with the history tables (History_Data and History_Queue) instead of the live tables (Live_Data and Live_Queue), while both have the same structure.
Any of the tables above has a primary key on a uniqueidentifier value (see listing below), thus automatically a clustered index on it:
Data:DataGuid
Live_Data:Live_DataGUID
MsgType:MsgTypeGUID
Live_Queue:Live_QueueGUID
History_Data:Live_DataGUID
History_Queue:Live_QueueGUID
The select query runs like endlessly, I stopped after a period of more than 10 minutes.
Execution plan
The execution plan can be regarded at the following PasteThePlan URI: Estimated Execution Plan
Note: I removed the nonclustered indices. I tried to add to start from the beginning again to get an idea how to begin systematically on this kind of slowmotion issues.
Any help is kindly appreciated, not only indexwise, but conceptually, too. Thank you.
sql-server index optimization
sql-server index optimization
New contributor
kvirk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
kvirk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 4 hours ago
MDCCL
6,85331745
6,85331745
New contributor
kvirk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked yesterday
kvirkkvirk
112
112
New contributor
kvirk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
kvirk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
kvirk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
How many records do you expect to get as a result?
– Akina
yesterday
The query above may return 500000-1500000 rows, although in the end, I do only need one row, specified by the idx value on V3 like SELECT A.Col1,B.Col1,C.Col1,A.Col2,B.Col2,A.Col3,B.Col3,C.Col3,A.Col4,A.Col5, D.Col1 FROM V3 WHERE idx = 4325324, with idx being a column of one of the tables of the query above.
– kvirk
yesterday
1
Insert this condition (WHERE idx = 4325324) by adding V3 view into your query source (FROM section or CTE)
– Akina
yesterday
1
SELECT * FROM V1 WHERE idx = 4325324 UNION SELECT * FROM V2 WHERE idx = 4325324. I hope the server is smart enough to insert the condition into subqueries and execute as the condition is in view text. PS. There is noidxfield in your view source text...
– Akina
yesterday
1
I would recommend defining yourv3view using the specific columns required from thev1andv2views. Using the potent*(asterisk) to select all column has the potential to break things should the viewsv1andv2change in the future.
– hot2use
15 hours ago
|
show 7 more comments
How many records do you expect to get as a result?
– Akina
yesterday
The query above may return 500000-1500000 rows, although in the end, I do only need one row, specified by the idx value on V3 like SELECT A.Col1,B.Col1,C.Col1,A.Col2,B.Col2,A.Col3,B.Col3,C.Col3,A.Col4,A.Col5, D.Col1 FROM V3 WHERE idx = 4325324, with idx being a column of one of the tables of the query above.
– kvirk
yesterday
1
Insert this condition (WHERE idx = 4325324) by adding V3 view into your query source (FROM section or CTE)
– Akina
yesterday
1
SELECT * FROM V1 WHERE idx = 4325324 UNION SELECT * FROM V2 WHERE idx = 4325324. I hope the server is smart enough to insert the condition into subqueries and execute as the condition is in view text. PS. There is noidxfield in your view source text...
– Akina
yesterday
1
I would recommend defining yourv3view using the specific columns required from thev1andv2views. Using the potent*(asterisk) to select all column has the potential to break things should the viewsv1andv2change in the future.
– hot2use
15 hours ago
How many records do you expect to get as a result?
– Akina
yesterday
How many records do you expect to get as a result?
– Akina
yesterday
The query above may return 500000-1500000 rows, although in the end, I do only need one row, specified by the idx value on V3 like SELECT A.Col1,B.Col1,C.Col1,A.Col2,B.Col2,A.Col3,B.Col3,C.Col3,A.Col4,A.Col5, D.Col1 FROM V3 WHERE idx = 4325324, with idx being a column of one of the tables of the query above.
– kvirk
yesterday
The query above may return 500000-1500000 rows, although in the end, I do only need one row, specified by the idx value on V3 like SELECT A.Col1,B.Col1,C.Col1,A.Col2,B.Col2,A.Col3,B.Col3,C.Col3,A.Col4,A.Col5, D.Col1 FROM V3 WHERE idx = 4325324, with idx being a column of one of the tables of the query above.
– kvirk
yesterday
1
1
Insert this condition (WHERE idx = 4325324) by adding V3 view into your query source (FROM section or CTE)
– Akina
yesterday
Insert this condition (WHERE idx = 4325324) by adding V3 view into your query source (FROM section or CTE)
– Akina
yesterday
1
1
SELECT * FROM V1 WHERE idx = 4325324 UNION SELECT * FROM V2 WHERE idx = 4325324. I hope the server is smart enough to insert the condition into subqueries and execute as the condition is in view text. PS. There is no idx field in your view source text...– Akina
yesterday
SELECT * FROM V1 WHERE idx = 4325324 UNION SELECT * FROM V2 WHERE idx = 4325324. I hope the server is smart enough to insert the condition into subqueries and execute as the condition is in view text. PS. There is no idx field in your view source text...– Akina
yesterday
1
1
I would recommend defining your
v3 view using the specific columns required from the v1 and v2 views. Using the potent * (asterisk) to select all column has the potential to break things should the views v1 and v2change in the future.– hot2use
15 hours ago
I would recommend defining your
v3 view using the specific columns required from the v1 and v2 views. Using the potent * (asterisk) to select all column has the potential to break things should the views v1 and v2change in the future.– hot2use
15 hours ago
|
show 7 more comments
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "182"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
kvirk is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f233166%2findexing-strategy-for-a-query-involving-three-views-multiple-columns-and-severa%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
kvirk is a new contributor. Be nice, and check out our Code of Conduct.
kvirk is a new contributor. Be nice, and check out our Code of Conduct.
kvirk is a new contributor. Be nice, and check out our Code of Conduct.
kvirk is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Database Administrators Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f233166%2findexing-strategy-for-a-query-involving-three-views-multiple-columns-and-severa%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
How many records do you expect to get as a result?
– Akina
yesterday
The query above may return 500000-1500000 rows, although in the end, I do only need one row, specified by the idx value on V3 like SELECT A.Col1,B.Col1,C.Col1,A.Col2,B.Col2,A.Col3,B.Col3,C.Col3,A.Col4,A.Col5, D.Col1 FROM V3 WHERE idx = 4325324, with idx being a column of one of the tables of the query above.
– kvirk
yesterday
1
Insert this condition (WHERE idx = 4325324) by adding V3 view into your query source (FROM section or CTE)
– Akina
yesterday
1
SELECT * FROM V1 WHERE idx = 4325324 UNION SELECT * FROM V2 WHERE idx = 4325324. I hope the server is smart enough to insert the condition into subqueries and execute as the condition is in view text. PS. There is noidxfield in your view source text...– Akina
yesterday
1
I would recommend defining your
v3view using the specific columns required from thev1andv2views. Using the potent*(asterisk) to select all column has the potential to break things should the viewsv1andv2change in the future.– hot2use
15 hours ago