Comments on: My wishlist for SQL: the UNTIL clause http://www.xaprb.com/blog/2010/01/22/my-wishlist-for-sql-the-until-clause/ Stay curious! Fri, 10 May 2013 18:25:19 +0000 hourly 1 http://wordpress.org/?v=3.5.1 By: Claus http://www.xaprb.com/blog/2010/01/22/my-wishlist-for-sql-the-until-clause/#comment-18535 Claus Tue, 03 Aug 2010 16:57:35 +0000 http://www.xaprb.com/blog/?p=1592#comment-18535 Never mind, just realized that doesn’t work for my use-case, as I’m not having a linear order here, so I can’t stop scanning even a sorted table when a certain condition is met.

]]>
By: Claus http://www.xaprb.com/blog/2010/01/22/my-wishlist-for-sql-the-until-clause/#comment-18532 Claus Tue, 03 Aug 2010 15:30:44 +0000 http://www.xaprb.com/blog/?p=1592#comment-18532 I just stumbled across a problem where an UNTIL clause would probably indeed make sense:

I have a column containing strings, and I want to find those strings that are a prefix to a given string:

E.g. If the given string is ‘Hello World’ then rows containing ‘Hell’, and ‘Hello’ should match.

A query like
SELECT * FROM table t WHERE t.str <= 'Hello World' ORDER BY t.str DESC UNTIL ('Hello World' NOT_STARTS_WITH t.str)
would archive that.

(whatever SQL-function corresponds to the NOT_STARTS_WITH predicate)

So in my case I want to physically iterate over the b-tree index, until some condition is no longer satisfied.

]]>
By: Monotonic functions, SQL and MySQL | code.openark.org http://www.xaprb.com/blog/2010/01/22/my-wishlist-for-sql-the-until-clause/#comment-17900 Monotonic functions, SQL and MySQL | code.openark.org Wed, 24 Feb 2010 21:50:37 +0000 http://www.xaprb.com/blog/?p=1592#comment-17900 [...] Baron’s wishlist for SQL can also benefit from monotonic [...]

]]>
By: Rob W http://www.xaprb.com/blog/2010/01/22/my-wishlist-for-sql-the-until-clause/#comment-17765 Rob W Mon, 08 Feb 2010 23:48:10 +0000 http://www.xaprb.com/blog/?p=1592#comment-17765 To me, I don’t think UNTIL is a very good idea:

1. The semantics of a “result set” is basically thrown out the window. A query is supposed to ask for data as if it were a set immediately available at the time of the query. Otherwise, you’re just using *procedural code* (which UNTIL just seems like perverting query syntax for the sake of an implicit loop). In other words, what about the halting problem? If you forget a WHERE clause, the worst case is you retrieve too much data. If you don’t make UNTIL have a sane terminating condition, then you can create an infinite loop. Depending on the database engine, this can cause a death spiral of locks, memory leaks, etc. The *semantics* of a query IS NOT a loop, so continuing a loop UNTIL some condition is non-sensical. You ask for the data, and based on the predicates the data either gets returned or they don’t, as a single result.

2. The argument that subqueries are doing too much whereas “one query” of UNTIL is faster is a non-argument. There IS NO “one query” for UNTIL: it’s semantically a loop of multiple queries (like you’d do with a procedure anyway). At least subqueries can be optimized by the planner. How is the query planner supposed to plan for something when there may not even be a genuine terminating condition?

But maybe there are genuine reasons for this, maybe either I’m not understanding or the concept isn’t being explained clearly enough. But then again, maybe that’s a sign that it’s not a good idea (given the list of problems stated already)?

]]>
By: Log Buffer #176: a Carnival of the Vanities for DBAs | The Pythian Blog http://www.xaprb.com/blog/2010/01/22/my-wishlist-for-sql-the-until-clause/#comment-17708 Log Buffer #176: a Carnival of the Vanities for DBAs | The Pythian Blog Fri, 29 Jan 2010 19:03:20 +0000 http://www.xaprb.com/blog/?p=1592#comment-17708 [...] Schwartz inspires a lot of conversation with his post, My wishlist for SQL: the UNTIL clause. Baron says, “I’d like an UNTIL clause, please. I’d use it sort of like LIMIT in MySQL and [...]

]]>