5 ms·
LAG/LEAD are basically SQL having to give in a little to the timeseries and column db people. It obliterates the set theoretic nature of SQL, and they are dog s
by jnordwick 10y ago
LAG/LEAD are basically SQL having to give in a little to the timeseries and column db people. It obliterates the set theoretic nature of SQL, and they are dog slow.
This is why any decent columnar/timeseries db has its own often arrish query language to take advantages of ordering information inherent in the data. There is an order in that index and SQL table, you just don't have good tools to access and use it.
This touches on a conversation I was having a couple weeks ago where somebody was saying that column/array storage is purely a backend consideration and don't need to care about it in the front end of the database. That view gets you ugly primitives like LAG/LEAD. Being able to exploit your backend decision is paramount to performance.
Products like Informix or KDB+ just give you full access to the data on and off disk as an array so you ca build complex windowing primitives (and even store them and reuse them later).
(PS: I just find this really funny. KDB+ is probably is the only database I know that literally does streaming analytics on a Raspberry Pi. No joke, the full DB on Linux ARM/Pi. https://kx.com/download/ https://kx.com/download/ )
- saurik 10y agoExciting! Can you point at something where one could learn about this specific feature of these kinds of databases? (Maybe like, "this is an example of that aspect of their syntax in particular, go read how it works", or "here is an article taking about how awesome this property is".)
- jnordwick 10y agoNot exciting. Most of the array processing / streaming facilities are steaming piles. You have Hadoop/MR and Monet in the OSS group. SysbaseIQ, KDB, Teradata, Vertica, VectorWise, etc. all provide either extended SQL or additional query support to use ordering information in some (often weak) way. You can even count Oracle In Memory Analytics with TSQL with its cursor model if you really want. For example for KDB to get the last price and sum of volumer for each second of AAPL you would do in KSQL: select last px, sum vol by time.second from trade where sym=`AAPL on it can be done in its lower level language K/Q as (approx, I'm a little rusty) g:group trade.time.second @ where trade.sym=`AAPL flip`px`vol!(last each trade.px g; sum each trade.vol g)
- thom 10y agoDo you know what the story is for using geospatial data with KDB+?
- jnordwick 10y agoThis is about the closest I know. Kx does a lot with utilities for metering and IoT stuff, but I haven't really kept up with that side of things as much as I do with the finance side. However I do know there are some using it for geospatial, and they are always eager to push into new areas so love the challenge. If a new datatype/index type needs to be done to support geospatial and be the fastest there, they are always up to the challenge. There were a couple really, really cool tech talks I've been to. The title alone gives it props :) "where Rumsfeldism & Kx collide" https://kx.com/2014/12/07/visualizing-really-big-data/ https://kx.com/2014/12/07/visualizing-really-big-data/ in case you're curious about one of the other: a polymer hypergrid with an absurd amount of real time updating data: http://openfin.github.io/fin-hypergrid-polymer-demo/components/fin-hypergrid/demo.html http://openfin.github.io/fin-hypergrid-polymer-demo/componen...
- aksyn 10y agohttp://code.kx.com/wiki/Cookbook/Geospatial http://code.kx.com/wiki/Cookbook/Geospatial
- lukaseder 10y agoI would be very surprised if LEAD and LAG couldn't profit from indexing, if you design your query / window function in a way that it actually can profit. Perhaps you're hinting at the idea that it's too easy to screw this up as a user, for it to be inefficient
- deleted 10y ago[deleted]
- jnordwick 10y agoThe doesn't help that much since you are probably already using an index for filter criteria, the table is probably unkeyed (fact table). The case it does work is that you are ordered on timestamp (for example), the query planner properly figures to use any filtering indexes and sequential indexes, ... magic occurs Now the job is making an SQL statement that the query planner can actual understand and optimize since SQL lacks so much of the machinery for order-dependent processing (this was a feature when SQL was conceived remember).
- deleted 10y ago[deleted]
- Jweb_Guru 10y agoEh, there's been work done on this, e.g. order dependencies. Not sure how much of it has made it into commercial SQL engines, though.
- jnordwick 10y agolink?
- Jweb_Guru 10y agoHere's one: https://arxiv.org/pdf/1208.0084v1.pdf https://arxiv.org/pdf/1208.0084v1.pdf (Note the involvement of IBM. Dunno whether this has made it into DB2, but a lot of really interesting research has; also keep in mind that whatever IBM wants to put in DB2 has a high probability of making it into the SQL standard).
- alfalfasprout 10y agoKDB+ is incredibly well designed, fast, and very mature. But it has one big problem. At $$$ / year (can't divulge pricing due to NDAs but it's > $10^4 for a very modest installation) you're talking about a massive expense if you want any kind of large deployment.
- jnordwick 10y agoI love KDB. When I first started, I hated it... with a fierce passion. I didn't see the point, but I was young and dumb and better looking. When the "Why's that company so big? I can do that in a weekend." article came out last week: https://news.ycombinator.com/item?id=12626314 https://news.ycombinator.com/item?id=12626314 I immediately thought of Kx and KDB and how it is literally the exact opposite. If people only knew how small the firm started with Arthur hacking away seemingly out developing entire corporations they would laugh. "Yeah give me about two years and a dev team of a about 20 then about 10 for QA and we've have something shippable... abother year or two for performance... 5 years we'll be in the hunt." Yeah, we'll this guy over here basically did it in six months with only two others. And it's 100x faster than anything else. Why can't you do that? Given his history too with A+ at Morgan Stanley, it wouldn't be the first time a team of a small handful he was at the core of beat the socks off everybody else either. Some people just have this amazing ability to see simplicity. I've had the pleasure of being around a few people boss like that.