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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Creating PostgreSQL Arrays Without A Quadratic Blowup

26 点作者 drob大约 11 年前

5 条评论

danbruc大约 11 年前
<i>A lot of languages handle this idiom more gracefully.</i><p>Actually they don&#x27;t. You can not resize a (static) array. What you really want is a dynamic array, an array list or whatever you like to call it. In this case you can double the size of the underlying array when you have to reallocate it and get the amortized runtime down but at the price of using up to twice the memory you need.<p>Maybe array_append is to blame because its pure existence somewhat implies that you are working with array lists and not with arrays.
评论 #7482226 未加载
kyllo大约 11 年前
<i>result := array_append(result, (&#x27;num=&gt;&#x27; || i)::HSTORE);</i><p>Yeah, I&#x27;ve never read a line of PLPGSQL before this, but I can tell by the assignment operator := that this is obviously creating a copy of the array every time you add an element to the array. This would also cause a quadratic blowup and&#x2F;or a memory blowup in any other language I&#x27;ve heard of, not just PLPGSQL. Anyone who has taken an introductory algorithms &amp; data structures class really should know better than to write code like this.
评论 #7482963 未加载
ScottBurson大约 11 年前
I think highly of Postgres, but this is disappointing. It&#x27;s well-known now how to implement functional array-like data structures with log-time concatenation. For a good summary see [0].<p>I think these techniques should be standard practice in programming language implementations.<p>[0] <a href="http://stackoverflow.com/questions/3271256/implement-an-immutable-deque-as-a-balanced-binary-tree/3274355#3274355" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;3271256&#x2F;implement-an-immu...</a>
评论 #7484907 未加载
klodolph大约 11 年前
Seems guilty of trying to do imperative programming in a relational database, then wondering why the performance is not good. Why use an array and not rows in a table?
评论 #7482234 未加载
dsugarman大约 11 年前
this is classic OO programmer programming SQL
评论 #7487960 未加载
评论 #7482852 未加载