Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12963

subselect with newid()

$
0
0

when I run an update sql like this one

update table1

set column1 = (select top 1 column1 from table2 order by newid())


the sql server run subselect once or many times (once for each row in table1) depend on how many rows are in table1.

I understand that is a good idea to cache subselect if it's doesn't contain any changeable data to optimize and boost performance of update sql, but in this case there is a "order by newid()" witch will order randomly and subselect will return random value for each row in table "table1", so will be better to have some hint for "don't cache subselect data" or to check subselect on parsing and if found newid() function call don't use cache.


Viewing all articles
Browse latest Browse all 12963

Trending Articles