Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Best way to query a list of IDs based on multiples booleans flags

Received: by 10.180.84.74 with SMTP id w10mr3706172wiy.4.1352216088660;
        Tue, 06 Nov 2012 07:34:48 -0800 (PST)
X-BeenThere: redis-db@googlegroups.com
Received: by 10.181.13.100 with SMTP id ex4ls1084601wid.0.gmail; Tue, 06 Nov
 2012 07:34:39 -0800 (PST)
Received: by 10.180.104.167 with SMTP id gf7mr530960wib.4.1352216079382;
        Tue, 06 Nov 2012 07:34:39 -0800 (PST)
Received: by 10.216.199.17 with SMTP id w17mswen;
        Tue, 6 Nov 2012 07:34:17 -0800 (PST)
Received: by 10.236.192.164 with SMTP id i24mr167351yhn.14.1352216057462;
        Tue, 06 Nov 2012 07:34:17 -0800 (PST)
Date: Tue, 6 Nov 2012 07:34:16 -0800 (PST)
From: Nicolas Bernard <nik...@nikkau.net>
To: redis-db@googlegroups.com
Message-Id: <c79fb1b5-ac1c-403d-9b02-83232938c2d5@googlegroups.com>
Subject: Best way to query a list of IDs based on multiples booleans flags
MIME-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_556_27397687.1352216056311"

------=_Part_556_27397687.1352216056311
Content-Type: multipart/alternative; 
	boundary="----=_Part_557_5456600.1352216056311"

------=_Part_557_5456600.1352216056311
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Hi,

I have a SQL table with some records (between 500 and 10 000, no big 
dataset, it might help later).

Each object stored in this table have booleans properties based on linked 
data in multiples another tables.

Now I need a way to query all objects with a given list of boolean flag but 
I don't like SQL and don't want complex SQL query.

My idea is to calculate all these flags from my data in a background job, 
store them in Redis and for each query, ask Redis intersection of a given 
list of flags, then I get back a list of IDs and I can do a simple regular 
query on my primary table.

What's the best way to achieve that?

I have 2 ideas :

- For each flag, store a list of IDs in a set, so I have just to ask a 
SINTER of all sets of my query.

- For each flag, store IDs as offset in a string with SETBIT, so I have 
juste to ask a BITOP AND of all sets of my query.

The concept is pretty much the same but the first is simpler and the second 
is much memory-efficient.

But what is the fatest? (I will intersect a max of 30 criterias)

If it's matters, that will happen in a LUA script.

Or maybe I have miss a third and better way?

(Sorry for my terrible english ;))

Thanks in advance.

--Nicolas

------=_Part_557_5456600.1352216056311
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hi,<br><br>I have a SQL table with some records (between 500 and 10 000, no=
 big dataset, it might help later).<br><br>Each object stored in this table=
 have booleans properties based on linked data in multiples another tables.=
<br><br>Now I need a way to query all objects with a given list of boolean =
flag but I don't like SQL and don't want complex SQL query.<br><br>My idea =
is to calculate all these flags from my data in a background job, store the=
m in Redis and for each query, ask Redis intersection of a given list of fl=
ags, then I get back a list of IDs and I can do a simple regular query on m=
y primary table.<br><br>What's the best way to achieve that?<br><br>I have =
2 ideas :<br><br>- For each flag, store a list of IDs in a set, so I have j=
ust to ask a SINTER of all sets of my query.<br><br>- For each flag, store =
IDs as offset in a string with SETBIT, so I have juste to ask a BITOP AND o=
f all sets of my query.<br><br>The concept is pretty much the same but the =
first is simpler and the second is much memory-efficient.<br><br>But what i=
s the fatest? (I will intersect a max of 30 criterias)<br><br>If it's matte=
rs, that will happen in a LUA script.<br><br>Or maybe I have miss a third a=
nd better way?<br><br>(Sorry for my terrible english ;))<br><br>Thanks in a=
dvance.<br><br>--Nicolas<br>
------=_Part_557_5456600.1352216056311--

------=_Part_556_27397687.1352216056311--