#189

Question. QueryPolicy.filterExp is use by 2nd index?

Openboojongminopened 5y ago

I read this https://github.com/aerospike/aerospike-client-java/issues/33?fbclid=IwAR2PBkdaDZKYXA15B50B9muK8M5f2YcdcyssbXysW8gADlA2wM17bfHbyaM

but I need search multiple bin with index.

aerospikeClient.createIndex(
    null, "hello", "hello",
    "idx_1", "hello1", IndexType.STRING,
    IndexCollectionType.DEFAULT
).awaitFirstOrNull()

aerospikeClient.createIndex(
    null, "hello", "hello",
    "idx_2", "hello2", IndexType.STRING,
    IndexCollectionType.DEFAULT
).awaitFirstOrNull()


val policy = QueryPolicy()
policy.filterExp = Exp.build(
        Exp.and(
            Exp.eq(Exp.bin("hello1", Exp.Type.STRING), Exp.`val`("asdf")),
            Exp.eq(Exp.bin("hello2", Exp.Type.STRING), Exp.`val`("defg"))
        ),
)

val v = aerospikeClient.query(policy, statement).awaitFirstOrNull()

is this code will use index?

and... how I know search rules like sql explain

thank you

Activity

4
BrianNichols5y ago

There is still a limit of one index filter (statement.setFilter()) per query, so either "idx_1" or "idx_2" could be used, but not both.

Expression filters (policy.filterExp) are applied after the index is used and can reference any combination of bins in the returned record. Therefore, your code should work, but only one index will be traversed.

boojongmin5y ago

@BrianNichols thank for your appreciate comment. It is many helps for me. :)

swapy1y ago

@BrianNichols does this mean if I have query with 2 conditions both Secondary indexed?

  1. With first condition it will get huge set of rows(as applicable), then on all that rows next condition will be applied one by one? It will not issue two conditions in 1 go as query to db
  2. If pt 1 is true, ordering of condition matters? How does it pick which SI to use? Can we handle this in code?
  3. Will it be more performant if we use only single SI to query, then filter in application itself rather than issuing query with 2 SI?

Please let me know

BrianNichols1y ago

@swapy

  1. Correct.
  2. The server determines which index to use.
  3. It can be more performant because the server can't choose the wrong SI to use.