是否可以优化特定表变量“值”?

时间:2019-05-27 14:35:14

标签: sql sql-server query-optimization

假设我在SQL Server 2016上运行以下查询:

Traceback (most recent call last):
  File "dcgan.py", line 83, in <module>
    disc_real = discriminator(input_disc_real, reuse=True)
  File "dcgan.py", line 70, in discriminator
    x = tflearn.fully_connected(x, 1024, activation='tanh')
  File "D:\python\lib\site-packages\tflearn\layers\core.py", line 157, in fully_connected
    restore=restore)
  File "D:\python\lib\site-packages\tensorflow\contrib\framework\python\ops\arg_scope.py", line 182, in func_with_args
    return func(*args, **current_args)
  File "D:\python\lib\site-packages\tflearn\variables.py", line 65, in variable
    validate_shape=validate_shape)
  File "D:\python\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 1479, in get_variable
    aggregation=aggregation)
  File "D:\python\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 1220, in get_variable
    aggregation=aggregation)
  File "D:\python\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 547, in get_variable
    aggregation=aggregation)
  File "D:\python\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 499, in _true_getter
    aggregation=aggregation)
  File "D:\python\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 853, in _get_single_variable
    found_var.get_shape()))
ValueError: Trying to share variable Discriminator/FullyConnected/W, but specified shape (62720000, 1024) and found shape (307328, 1024).

现在让我们假设我要{@ {1}}的@Ids表的特定“值”。 甚至有可能提供这样的提示吗?我尝试过declare @Ids as table ( Id int ) -- Insert some values into @Ids table select * from dbo.Foos where FooId in (select Id from @Ids) ,但无法编译

预先感谢

1 个答案:

答案 0 :(得分:1)

否,您不能以这种方式使用该选项。让我们看一下文档:

  

优化(( @variable_name {未知| = literal_constant })[,   ... n])指示查询优化器为 a 使用特定值   编译和优化查询时局部变量。值是   仅在查询优化期间使用,而不在查询执行期间使用。

     

@variable_name 是查询中使用的本地变量的名称,可以为其分配值以用于OPTIMIZE FOR查询   提示。

因此,该选项用于局部变量,而不是用于表变量,这是完全不同的事情。

Hints (Transact-SQL) - Query