If I have a view in SQL which contains various computed columns, some of which could be very expensive, but only select a few columns out at any one time will I be taking any more of a performance hit, than if I was to separate the views out to multiple views and use them individually?
For example if I have 5 columns in my table, and my view contains those same 5 columns, but also 10 simple computed columns and 10 expensive computed columns (using averages or similar) and decide to only select out one or two of the simple computed columns, would I expect that to be any more expensive than if I had separated the expensive columns into their own view?
Edit:
I'm specifically interested in answers regarding SQL Server and Postgres databases, but a more general response if appropriate will suffice.
Edit2:
I've looked at query plans in SQL Server and it appears to not bother making a plan for the computed columns when they aren't selected, so I'm hopeful that it's fine to combine all the columns into one view, but would like confirmation :D
Edit 3:
@NaveenBabu I don't have any performance problems yet - this is somewhat hypothetical. The extra columns will mostly be things like: DATEPART(mm, aDateField), DATEPART(dd, aDateField) ie. simple cheap extensions to the table. But there will be more complicated expensive columns like: (SELECT COUNT(*) FROM events WHERE events.iTicket = tickets.iCode) as NumberOfEvents
So I guess if you want a generic example the view would be:
CREATE VIEW TicketsView AS
SELECT
tickets.idx, tickets.a, tickets.b, tickets.c, tickets.d,
DATEPART(mm, a) as ticketMonth, DATEPART(dd, a) as ticketDay,
DATEPART(yy, a) as ticketYear,
(SELECT COUNT(*) FROM events WHERE events.iTicket = tickets.idx) as numEvents
FROM tickets
Or something like that. The last column is clearly more expensive than the others so: If I SELECT tickets.idx, tickets.b, tickets.ticketMonth FROM TicketsView will it need to do the subselect / count to calculate numEvents, as I haven't selected it out from the view?
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)