简体   繁体   English

在查询执行期间,是否可以根据需要评估SQL绑定的任何方式/平台?

[英]Is there any way/platform on which SQL binds can be evaluated as-needed, during query execution?

Context: 内容:

Say I have a large query (pseudo): 假设我有一个大型查询(伪):

SELECT %boundthing,data
WHERE data in (
    ...do lots of long-running stuff
)

Let's assume boundthing isn't being used in my query anywhere but when I want to print the output (I know it's a stupid use case, but it illustrates the point that I know boundthing won't be needed until after the WHERE clause runs). 让我们假设在我的查询中没有使用boundthing ,而是在我想打印输出时使用(我知道这是一个愚蠢的用例,但这说明了我知道直到WHERE子句运行后才需要boundthing )。 。

As it is, if I pass the value for boundthing to my query in the programming language of my choice, it's evaluated when I fire the query off, regardless of how much later on it will actually be "used" by the database. boundthing ,如果我使用自己选择的编程语言将boundthing的值boundthing给查询,则当我触发查询时,将对它进行评估,而不管数据库实际将使用该查询多少时间。

Question: 题:

Is there a way (in an existing database/programming language) to set a bind-style thing to be evaluated (that is, it produces a value for the bound variable, whether the source is a variable or a function) on-demand in a query, rather than when the query plan is built? 是否有一种方法(在现有的数据库/编程语言中)可以按需设置要评估的绑定样式的东西(即,它为绑定变量生成一个值,无论源是变量还是函数)查询,而不是构建查询计划时?

For example, I could say, in application pseudocode: 例如,我可以在应用程序伪代码中说:

function MyFunc:
    return "foo" + system.GetEpochTimestamp();

var results = database_handle.Execute( SQL = "
    SELECT %boundthing,data
    WHERE data in (
        ...do lots of long-running stuff
    )", BINDS = [ ("boundthing", MyFunc ) ]
);

And the value of "boundthing" in the output would correspond to the timestamp on the application server, after the WHERE clause filtered everything (minus the runtime of myfunc on the application server, and however long it took for the data to make it to the database server and be processed by the database). 并且在WHERE 子句过滤了所有内容之后 (减去应用程序服务器上myfunc的运行时间,但是将数据存储到数据包中花费的时间很长),输出中的“ boundthing”值将与应用程序服务器上的时间戳相对应。数据库服务器并由数据库处理)。

Why I want to know: 为什么我想知道:

Curiosity. 好奇心。

I know that something like this would probably destroy a lot (maybe all) of the efficiency lent by a query planner. 我知道,类似这样的事情可能会破坏查询计划人员借出的很多(也许全部)效率。 I know that you would never have a guarantee that the evaluation of the bind would be executed exactly when the value was needed in the query (there's value transmission time, processing time on the database, etc). 我知道您永远无法保证将在查询中需要值时(确切的是值传输时间,数据库处理时间等) 准确执行绑定的评估。 I also know that it violates a lot of atomicity guarantees and could cause serious problems in the event of an abort or outage. 我还知道,它违反了许多原子性保证,并且在中止或中断的情况下可能引起严重的问题。

Still, I'm curious. 不过,我很好奇。

CREATE PROC MyFunc
AS
BEGIN
    SELECT * INTO #MyTempTable FROM data where data in ( ...do lots of long-running stuff);
    $boundthing='EXEC boundthing'
    select $boundthing, * from #MyTempTable
END
GO

Hope that helps Zac. 希望对Zac有帮助。

-Pete -皮特

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否会在 ZE0626222614BDEE451951D84C6 - Will SQL Select query select record which was inserted during Select query execution? SQL:在执行查询期间记录显示空白 - SQL: Records showing blank during the execution of a query 有没有什么方法可以编写和执行动态查询而不在字符串模式下执行SQL查询 - Is there any way to write and execute dynamic query without execution SQL query in string mode 有什么办法可以给 SQL 中的函数指定一个名称,以便以后引用? - Is there any way to assign a name to a function in SQL which can be referenced later? SQL查询中是否有任何特定的执行顺序? - Is there any specific order of execution in SQL query? 有什么办法可以缩短这个 SQL 查询 - Is there any way to shorten this SQL Query 执行从 SQL 转换而来的 Doctrine DQL 查询时出错 - Error during execution of a Doctrine DQL query converted from SQL 在自动化中存储执行期间使用的 sql 查询的最佳方法是什么 - What is the best way to store the sql queries used during execution in Automation 获取错误为“SQL 查询执行期间发生错误” - Getting Error as "Error occurred during SQL query execution " SQL查询-在查询中注入的函数将由Oracle评估 - SQL Query - are functions injected in a query will be evaluated by Oracle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM