question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Decide on sort order

See original GitHub issue

@Level/core The way that memdown compares keys is starting to show its limitations. To fix that (or not) we have a few options. The goal is to increase ecosystem compatibility (like integrating with subleveldown), which doesn’t necessarily mean “behave exactly like leveldown”.

1. Keep memdown as-is.

Drawback: you can only safely use one key type in your db. When mixing types - e.g. db.put(str) followed by db.put(buf) - keys may unexpectedly be treated as equal. This issue exists with strings vs buffers, strings vs numbers and more.

Ref: https://github.com/Level/subleveldown/issues/64, https://github.com/Level/level-ttl/issues/68#issuecomment-480505112, https://github.com/Level/community/issues/58#issuecomment-487354041, https://github.com/Level/abstract-leveldown/pull/310 and possibly https://github.com/noffle/kappa-view-level/commit/fdf775de76abdffdcbbd73a2318de08a55bd0ec1.

2. Bring memdown closer to level-js, by sorting keys by type first, then content (#185)

Mixing types in your db is OK. The behavior does however differ from leveldown, where buffers and strings are both stored as byte arrays, while memdown will sort and store them separately. For example, db.put('a') will write to a different key than db.put(Buffer.from('a')).

3. Bring memdown closer to leveldown, by storing everything as a Buffer.

Drawbacks: conversion cost (especially when you’re solely working with strings, which is common), reduced type support.

4. Bring memdown closer to leveldown, by comparing strings and buffers bytewise

Possibly combined with #185, I don’t know what it would look like. Downside: this will be a third distinct behavior, sitting in between leveldown and level-js. Alternatively (and radically) we could drop support of key types other than strings and buffers.

5. Long-term: bring encodings into abstract-leveldown (https://github.com/Level/community/issues/58)

This could potentially allow implementations to be smarter about how they store and return types.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
vweeverscommented, Aug 10, 2019

I propose the following changes:

  • Drop key types other than strings and buffers from memdown and level-js. If someone wants that type support back, they can fork. Long-term we may bring back some of the functionality in another form, depending on what we do with encodings and the merger of abstract-leveldown with levelup.
  • In memdown, store strings as buffers. We’ll only need one simple comparator. Prefer compatibility over raw performance. If someone doesn’t like the conversion cost, they can fork (or go lower-level, i.e. using functional-red-black-tree directly).
  • In level-js, store strings as (array)buffers. Continue to use IndexedDB’s native comparator.

The custom type support was a worthwhile experiment IMO that incidentally helped to clean up code overall. In absence of actual usage, we can end this experiment. This GH thread has been open long enough for people to raise objections.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Choosing Sort Order: Best Practices - Vertica
Choosing Sort Order: Best Practices · Combine RLE and Sort Order · Maximize the Advantages of RLE · Put Lower Cardinality Column First...
Read more >
Improving the Sort Order on Category List Pages
The most common way to do so is by clicking on a drop-down select element and choosing their preferred new sort order.
Read more >
Sort and arrange items in the Finder on Mac - Apple Support
Sort items: In any view, choose View > Show View Options, click the Sort By pop-up menu, then choose the sort order, such...
Read more >
Sort data using a custom list - Microsoft Support
Select the columns to sort. · In the ribbon, click Data > Sort. · In the Sort popup window, in the Sort by...
Read more >
Choose the best sort key - Amazon Redshift
Amazon Redshift stores your data on disk in sorted order according to the sort key. The Amazon Redshift query optimizer uses sort order...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found