Sort LDT by secondary index

Hi, is it possible to sort data in LDT BIN by secondary index?

Hi Max, the question seems a little fuzzy, can you please elaborate? What are you trying to insert into an LDT? What do you mean by sorting an LDT BIN?


Hi, I need to sort record in Large ordered list, now I sort it by primary key, but I need to sort by other bin, let it be PRIO-BIN, for example:

key             | PRIO | data
key-of-record-1 | 1    | some data
key-of-record-3 | 1    | some data
key-of-record-2 | 2    | some data
key-of-record-4 | 2    | some data

Assuming that key column denotes the keys in the LDT bin there is no explicit way to sort based on PRIO. But, you can do a work around by prefixing the current key with respective PRIO value and store it in the LDT BIN. This would ensure the sorting order you intend to get.


 key               | PRIO     | data

1_key-of-record-1  | 1        | some data

Yes, I do it so, but I have a problem with unique records because the same record may be with different PRIO. I have no way to check if record with the any prio exist in store or not, because 1_keyrocrdhas 2_keyrecordhash is diffent pk.


You seem to be attempting to achieve sorted set behavior. Only possible way to achieve this would be to maintain 2 LDT bins. One for the uniqueness constraint and other to maintain sort order. It would look like

bin1 keyrocrdhas -> 1_keyrocrdhas bin2 1_keyrocrdhas -> values

While updating you can lookup the key in bin1 and then jump to bin2 to delete old value 1_keyrocrdhas and insert new value <new_priority>_keyrocrdhas.

You can manipulate both the LDT under single transaction running llist.* commands from inside UDF.

HTH – Raj

1 Like

good idea, I will try it, thanks

© 2015 Copyright Aerospike, Inc. | All rights reserved. Creators of the Aerospike Database.