Hacker News

Top stories

Live mirror
30 storiesupdated just nowView source snapshot
  1. Jemalloc 5.4.0(github.com/jemalloc ↗)
    27comments
  2. The scourge of x86 emulation(fex-emu.com ↗)
    13comments
  3. Astra for Law(openai.com ↗)
    509comments
  4. Bonsai 2 27B: Near-Lossless Compression in a 9x Smaller Footprint(prismml.com ↗)
    125comments
  5. When the fractional part of a float fixes your shader(crocidb.com ↗)
    discuss
  6. Bend – A language that blocks AI mistakes via proof, on CPU and GPU(bend-lang.com ↗)
    209comments
  7. Qwen 3.8 Omni Flash(qwen.ai ↗)
    72comments
  8. Hister: A private search engine for the pages you visit and the files you keep(github.com/asciimoo ↗)
    162comments
  9. Pre-Greek: The lost language hidden within Ancient Greek(linguisticdiscovery.com ↗)
    30comments
  10. Wax motor(wikipedia.org ↗)
    66comments
  11. A heap overflow and SSO misconfiguration to compromise OpenAI internal repos(hacktron.ai ↗)
    133comments
  12. Fujitsu launches made-in-Japan next-generation CPU FUJITSU-MONAKA(global.fujitsu ↗)
    227comments
  13. Shapelearn Qwen 3.8 27B (13.1 GB VRAM)(byteshape.com ↗)
    7comments
  14. How to Write with an LLM(sockpuppet.org ↗)
    85comments
  15. Ask A Monk – A digital wilderness for thoughts with no immediate answer(askamonk.online ↗)
    20comments
  16. Why Does the Universe Expand?(cosmicave.org ↗)
    49comments
  17. Flet 1.0 – Build cross-platform apps in Python(flet.dev ↗)
    52comments
  18. Telstra outage: The night a network decided the year was 2006(netnod.se ↗)
    23comments
  19. Speeding up gearhash on ARM64(sam.dev ↗)
    discuss
  20. Diplodocus, Long Thought Exclusively American, Turns Up in Spain(sci.news ↗)
    37comments
  21. The most important product decision is what you don't build(liamnugent.me ↗)
    35comments
  22. Fixing an NZXT Signal 4K30 part 2: the green/pink video bug(downtowndougbrown.com ↗)
    9comments
  23. Why I didn’t sign the Fields medallists’ letter(gowers.wordpress.com ↗)
    362comments
  24. CrowdSec Source Code Leak(crowdsec.net ↗)
    46comments
  25. Khipu (Quipu) Field Guide(khipufieldguide.com ↗)
    discuss
  26. Apple detectives solved mystery of ancient tree and rewrote the history of fruit(scientificamerican.com ↗)
    5comments
  27. How do we prevent mathemathics from devolving into the Medieval Era of secrecy?(mathoverflow.net ↗)
    104comments
  28. Show HN: Snapdrop: Instantly share files between devices. No setup, no signup(snapdrop.me ↗)
    34comments
  29. How Uber Protects Against Retry Storms(uber.com ↗)
    38comments
  30. Infinite-Parameter LLMs: Generating and Adapting Weights from Live Data(arxiv.org ↗)
    39comments

Faster DISTINCT queries on PostgreSQL

100 pointsby 5y agoblog.timescale.com
13 comments
5y agoHN ↗

Does anyone know why something like binary search isn't a first simple choice for skipping to the next unique item, if the index is ordered?

Is it because of the tree structure of the index?

5y agoHN ↗

Very rough sketch.

Say you have a table with two rows. One is time, the other is temperature. Your table is sorted by time, but you want all the unique temperatures.

Given the temperatures are unordered, you can't perform a binary search. If you also create a proper index against the times, your temperatures will also live in leaves of a tree that you'll need to access to get the values.

So trick 1 is to just index that column, like you said, a precomputed binary search if you will But since we're interested in distinct queries, we can optimize further by pointing to the next greatest value with the index tree too (hence skip scan.)

5y agoHN ↗

Say you have a table with two rows

You mean two columns, right?

5y agoHN ↗

(Disclaimer: I'm an engineer at Timescale, I didn't work directly on this feature but have some knowledge of what it does).

I'm not 100% sure I understand exactly what you're asking, but, perhaps some more info will be useful. First off, the goal with this isn't just to find the next unique item, it's to find the set of all the unique items, so you'd need to iterate the search, which is basically what the skipscan is doing internally.

Internally, the index is using something like a binary search (it's a btree, so slightly different, IIRC) to skip to the next unique item. A lot of the work here was in teaching the planner / executor to actually do that rather than the simpler, less efficient way that PG usually does it (brute force unique over a full scan). There's some more complexity on top of that in terms of teaching it to do that over all the chunks and then combine the results (because each has a separate index) and some more complexity in terms of knowing when you can use multi-column indexes and the like, but at its most basic level, it basically is using some sort of binary search to find the next item. But perhaps I'm missing what you're asking, feel free to clarify if I can better help here...

5y agoHN ↗

If index is ordered, I imagined it as a flat array. I would go to the next bigger item using binary search. I guess SkipScan does a similar thing but the index is a btree.

Of course, things get more complicated when more tuples need to be distinct but I was a bit confused as to why the ordered property was not exploited by PG before (and still is not).

5y agoHN ↗

Walking a btree just is binary search (effectively, although btrees have more than two branches and leaves)

5y agoHN ↗

I've been considering TimescaleDB for some use cases. Specifically to keep a transactional log of messages sent out.

Has anyone independently benchmarked TimescaleDB vs Postgres w/ B-Tree vs Postgres w/ BRIN? Given that most timescale data would benefit greatly from BRIN, I'm surprised their various blog posts never cover it.

I have discovered one person who tried to replicate some of the benchmarks around Postgres vs TimescaleDB (back in 2019), but they came up with data that contradicts the latest blog post around TimescaleDB vs Postgres performance, which makes me reconsider whether I really need what TimescaleDB provides. Maybe there have been large changes since then?

http://blog.coelho.net/database/2019/09/13/postgresql-vs-tim...

https://blog.timescale.com/blog/timescaledb-vs-6a696248104e/

5y agoHN ↗

If you have a real use case, just build it with vanilla pg. Once you start feeling pain with pg, migrate to timescale and see what happens.

You may never end up needing the performance boost they advertise.

5y agoHN ↗

I'll just add it's extremely easy to migrate, pg_dump and then just load it back up.

5y agoHN ↗

What exactly is Timescale DB, is it built on top of Postgres or a plugin for postgres or postgres API compatible DB built from ground up?

5y agoHN ↗

TimescaleDB is implemented as an extension on Postgres, so native Postgres runs underneath.

("Underneath is not really the right way to think about it, because the extension model lets us hook into lots of different places in the Postgres code -- TimescaleDB generates a shared library .so, implemented in C, so runs in same process/memory space.)

But, the great thing of this is as Postgres improves, so does TimescaleDB. TimescaleDB launched with Postgres 9.6, and now supports Postgres 13 and all the great improvements that have been implemented between those two PG versions.

5y agoHN ↗

I made first tests with Timescale 10 days ago with logs of a website. First result, I was impressed by the compression: 13GB of compressed CSV files - 1 PostgreSQL table of 63GB - 1 Timescale hypertable of 4GB. Then, I saw improvements on the performance of my queries, between 23% and 92% faster on the hypertable versus the table. This is definitely interesting and I will look into it further. I'm getting from "it's not a good idea to put weblogs on Postgresql" to "why not, if it helps simplify our infra".