← Back to context

Comment by prathje

11 hours ago

Interesting concept which reminds of the operations available in pandas.

I disagree though with the statement of SQL needing 20 lines. The given query feels verbose and has lots of redundant conditions. Not saying that it is short but a better analogy could look like this:

SELECT DISTINCT an.name, t.title

FROM keyword k

JOIN movie_keyword mk ON mk.keyword_id = k.id

JOIN title t ON t.id = mk.movie_id

JOIN movie_companies mc ON mc.movie_id = t.id

JOIN company_name cn ON cn.id = mc.company_id

JOIN cast_info ci ON ci.movie_id = t.id

JOIN aka_name an ON an.person_id = ci.person_id

WHERE k.keyword = 'character-name-in-title' AND cn.country_code = '[us]';

I would go one step farther: the SQL is awkward and long because the SQL language not at all optimized for data that is normalized all the way to binary relations.

And if you’re trying to benchmark one of these binary relationship query tools against DuckDB, keep in mind that DuckDB is heavily optimized for wide tables and is really not heavily optimized for point queries.

(Also, I, personally, would be a bit unhappy with a DBMS that cannot express, as part of the schema, that a movie has at most one or exactly one title.)