LucidDB / luciddb

DEFUNCT: See README
https://github.com/LucidDB/luciddb
Apache License 2.0
52 stars 24 forks source link

[FRG-53] support for state-saving across user-defined routine invocations #817

Closed dynamobi-build closed 12 years ago

dynamobi-build commented 12 years ago

[reporter="jvs", created="Tue, 21 Feb 2006 15:12:09 -0500 (GMT-05:00)"] It is often useful to be able to maintain state across invocations of a UDR. The most common case is when precompilation is used as an optimization. For example, a UDF may take a regular expression as a literal parameter, compile an instance of java.util.regex.Matcher, and use it to process another parameter for each invocation. Another use is for writing non-deterministic UDR's (e.g. a random-number generator UDF which needs to use the same underlying java.util.Random object across invocations).

The SQL standard external routine mechanism only allows binding to a static method, without any notion of context across invocations. Static data members are not a good solution because (a) they can be accessed from multiple threads, so they require synchronization, and (b) they can result in memory bloat since a UDR class which maintains a map or pool has no information about when an object is no longer needed (other than garbage collector memory pressure if something like a SoftHashMap is used).

The proposed feature is to enhance Farrago's runtime system to address this requirement, because Farrago has the best notion of what's going on during execution. To the UDR, it would look something like thread-local storage: the ability to set an Object value, load the current value, and receive a notification to deallocate any associated resources (when query execution completes). The actual interface remains to be defined; it will be a class with static methods. FarragoRuntimeContext would take care of context-switching by setting a real thread-local before each UDR invocation, so that each usage of a UDR within a particular running instance of a SQL statement would see its own private state. For example, in the following query,

select rand() as x, rand() as y
from t;

the two rand usages would have independent state (as would any executions of the same cached query from other sessions).

Note that reliance on this feature would make a UDR implementation dependent on Farrago (i.e. not portable to other SQL implementations).

dynamobi-build commented 12 years ago

[author="jvs", created="Sun, 26 Feb 2006 17:39:44 -0500 (GMT-05:00)"] We can also use this internal interface for access to FarragoDatabase, so that management views don't need to rely on FarragoDbSingleton.

dynamobi-build commented 12 years ago

[author="jvs", created="Mon, 6 Mar 2006 21:32:19 -0500 (GMT-05:00)"] Sunny brought up the related case of a foreign data wrapper which uses a UDX for its implementation and needs to pass it an object (such as a webservice binding) at runtime.

Perhaps in this case we can arrange for the state to be predefined with the result of foreignServer.getRuntimeSupport(null) so the UDX can just look it up on entry. This requires a refinement of FarragoJavaUdxRel which knows about foreign servers and takes care of the necessary codegen.

dynamobi-build commented 12 years ago

[author="jvs", created="Tue, 7 Mar 2006 08:51:36 -0500 (GMT-05:00)"] Everything except Sunny's request is implemented by eigenchange 5715.

dynamobi-build commented 12 years ago

[author="elin", created="Tue, 7 Mar 2006 11:01:01 -0500 (GMT-05:00)"] Ok thanks John. LDB-44 created to keep track of changes for the applib udrs.

dynamobi-build commented 12 years ago

[author="jvs", created="Tue, 7 Mar 2006 21:20:53 -0500 (GMT-05:00)"] A feature to satisfy Sunny's request is available in eigenchange 5725.