Hacker News new | past | comments | ask | show | jobs | submit login

As an outsider, my initial reaction is "does every new database system have to come up with their own SQL-like language?"



SQL's only virtue is that it is well known; It is otherwise not very good compared to other query languages, and every SQL engine extends it somewhat differently, extensions which you can't avoid cause the standard is too limited. I agree most query languages would be better off as minor extensions to SQL - but kdb+/Q is different.

Unlike SQL which pays lip service to Codd's relational model but breaks it with things like TOP, ORDER BY, LIMIT and others, the Q language embraces the order between tuples to great effect, making e.g. "as-of" queries which are quite common trivial; whereas in SQL and the relational model, as-of queries are inefficient in either execution time or storage space (usually both), and reasonable execution speed schemas cannot, in fact, guarantee their integrity (which is often quoted as one of the the main advantages of the relational model).

As another example, Q implements "foreign key chasing" also called "reference chasing", which is also implemented in the web2py DAL and surely others; compare[0] the equivalent tpc-h query:

in q:

   select revenue avg supplier.nation=`BRAZIL by order.date.year from lineitem
    where order.customer.nation.region=`AMERICA, order.date.year in 1995 1996, part.type=`STEEL
in sql:

   select o_year,sum(case when nation = 'BRAZIL' then revenue else 0 end)/sum(revenue) as mkt_share
   from(select year(o_orderdate) as o_year,revenue,n2.n_name as nation
    from part,supplier,lineitem,orders,customer,nation n1,nation n2,region
    where p_partkey = l_partkey and s_suppkey = l_suppkey and l_orderkey = o_orderkey
     and o_custkey = c_custkey and c_nationkey = n1.n_nationkey
     and n1.n_regionkey = r_regionkey and r_name = 'AMERICA' and s_nationkey = n2.n_nationkey
     and o_orderdate between date('1995-01-01') and date('1996-12-31') and p_type = 'STEEL') 
    as all_nations group by o_year order by o_year;
[0] bottom of http://kparc.com/d.txt




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: