Need help reqarding sql view

I have a eccomerce website it has 30000 thousand product.i Have created view for product fetching in main website called View_Product
Now i am creating query like
Select Top 10 * from View_Product Does this query return all 30000 product load and then it show only 10 row or it only fetch 10 row from view .i am asking this question because my website is running slow
Does using row number funtion or top funtion on large amount of data view slow down query
Plaese help me

The view has to be built before the top 10 can be found from there.

i Have build view before top 10 .i have only question of speed does calling 30000 product view
top 10 product take a load of 30000 product or not

If the view can load up to 30,000 products, then yes, it will load the full 30,000 rows before the top 10 can be selected from them. That’s the problems with views - they are built dynamically at run time, and all of the typical table type benefits (indexes, etc) aren’t cached, so the whole thing needs to “built” (hence my previous post) before selections can be made from there.

Thanks Sir for answer this was i was looking for
does you recommended me to use view here if product are not more than 50000 thousand

want a different answer that you might like even more?

do an EXPLAIN on your query to see why your query is slow, and then think about ~which~ 10 rows you want

because TOP makes no sense unless you have an ORDER BY clause, and an ORDER BY clause is not efficient unless there’s an index on the column(s) involved

1 Like

a view is nothing more than saved SQL code – so the table’s indexes ~do~ influence whether a query on a view is efficient

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.