Reinvention of Triggers - Signals #71912
Replies: 1 comment 1 reply
-
Thanks for this thoughtful write up!
For this use case, CockroachDB supports the
Both of these use cases, and the ideas you describe about Streaming SQL APIs sound very much like CockroachDB's CDC (Change Datafeed Capture) feature. See the docs: https://www.cockroachlabs.com/docs/stable/stream-data-out-of-cockroachdb-using-changefeeds.html
|
Beta Was this translation helpful? Give feedback.
-
Instead of implementing the SQL Trigger API first, I suggest that Reinventing "Data event" mechanisms should happen first with a new API, and then legacy SQL Trigger API will be able to build upon that.
Triggers AND External-Queue systems (like RabbitMQ) needed a rethink anyway. Programmers want to use a real programming language to complete work, not Procedural SQL. Given that Cockroach is a distributed system, this is a good opportunity to reevaluate the needs that SQL-Triggers and External-Queue systems are satisfying - derive the underlying reasons and requirements.
[1] could be better handled with Built-In column types for such cases. If the timestamp is already captured for each change in the engine (which I think it is), then such an UpdatedAt column only needs to display that information. It would naturally be a read-only column. Nice. For UpdatedByID, this should be something also handled internally by the engine. Both the database-user-id AND an application-asserted-id should be recorded.
[2] should also be handled by the system. It's just a simple log of transactions. But an API should be presented that enables digestion of that log into different forms.
[3] The first step toward an "after" trigger should be limited only to "signalling". The CockroachDb cluster network only communicates the availability of new data for a particular table or partition(by row index). Any consideration for relaying the actual data should be postponed. Because instead, when a process is signalled, it should then Query to get the new data (according to defined JOINs and filters(where)).
Signalling foundation
Even better, there should be a Streaming SQL API for this
select * from StreamView_Sales_Inserted where SaleAmount > 10000;
In which case, the View is a system-defined-stream-view that uses system-defined-signals. That is
StreamView_Sales_Inserted
would rely on theInserted
signal on themydb.Sales
table.The user should be able to directly use multiple system-defined-stream-views to create custom composite stream-views. (But also, the user should be able create stream-views from scratch, where the Signals are referenced explicitly by the user (TBD))
Example usage:
Such a streaming SQL query should be able to use the same Database Connector API. For example, in C#, the
Read()
function would block until a new record was available from the server. The server would be able to store the SQL query and other meta-data about results, then upon Signal, it can re-run the query and only send new records to the DB Connection client. A simplistic timestamp mechanism could be used for windowing of results, which would also allow older records to be resent if they were updated.Conclusions
I still think that traditional SQL-Triggers would need to be supported. There would still be cases where such procedures need to be run upon INSERT/UPDATE/DELETE on the node that is running that Command. But I believe the bulk of the requirements can be shifted to better APIs and mechanisms given what we know today about building software systems.
What do you think? Would this be an improvement on the traditional SQL-Triggers foundation?
Beta Was this translation helpful? Give feedback.
All reactions