TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Degrees of Kevin Bacon Using Postgres

87 点作者 pramsey9 个月前

10 条评论

its_bbq9 个月前
They call the dijkstra implementation slow but that's because they aren't using the full information it presents. Dijkstra gives shortest paths from one node to every other node in the graph, so you run it once and materialize it and now you have a full Kevin Bacon database
评论 #41347058 未加载
jtwaleson9 个月前
Couldn’t you “just” create a nullable distance column and update anything that’s null and reachable by Bacon and set it to 1. Then update anyone still null and reachable by 1 to 2, etc. Then you have a materialized view of everyone’s Bacon number.<p>Not a generic solution of course, but seems extremely effective for the Bacon case.
mdp20219 个月前
Very, very good: perfect for didactic. I thought I&#x27;d try this on SQLite, but I am in a rush right now... So I checked the documentation to refresh my memory about the extent of relevant SQL implementation in SQLite, and...<p>TIL that the &#x27;WITH&#x27; clause in SQLite can draw the classic Mandelbrot Set:<p><a href="https:&#x2F;&#x2F;www.sqlite.org&#x2F;lang_with.html#outlandish_recursive_query_examples" rel="nofollow">https:&#x2F;&#x2F;www.sqlite.org&#x2F;lang_with.html#outlandish_recursive_q...</a><p>(And there is a Sudoku puzzle solver below that.)
jnordwick9 个月前
Now do the Erdos number: defined the same way but for coauthors of papers linked to the absurdly production (and always high on amphetamines) great Paul Erdos. The most glorious of all, the Erdos-Bacon number, is defined as the sum of your Bacon number and Erdos number.<p>Mathematicians Daniel kleitman and Bruce Reznik both tie for top spot with a number of 3 (Erdos 1s and Bacon 2s). Danica McKellar and Elon both in there with 6s. And Mayim Bialik, Natalie Portman, and Kristen Stewart all up there with 7s.<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Erd%C5%91s%E2%80%93Bacon_number" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Erd%C5%91s%E2%80%93Bacon_numbe...</a>
评论 #41347261 未加载
robryk9 个月前
I don&#x27;t see why one has to create the actor-actor relation table. I would rather search for shortest paths in the bipartite graph where nodes are movies and actors, and divide the results by 2.
harel9 个月前
That&#x27;s all very cool. As an aside I always remembered the bacon number was between Bacon and anyone else, Hollywood actor or not. Keeping it withing Hollywood makes a lot more sense.
评论 #41345852 未加载
orthoxerox9 个月前
Oracle&#x27;s CONNECT BY is much easier to write and understand than recursive CTE. It&#x27;s a pity it&#x27;s not standart.
anotherevan9 个月前
For slow changing, read-heavy scenarios like this, make your recursive CTE a materialised view and whack some indexes on it for big performance gains.
mr_mitm9 个月前
Is there something like Cypher that can be leveraged to make the queries against a postgres graph a bit more digestible?
willf9 个月前
Let’s normalize recursive CTEs.