aerospike / aerospike-client-java

Aerospike Java Client Library
Other
236 stars 212 forks source link

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

Open boojongmin opened 3 years ago

boojongmin commented 3 years 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

BrianNichols commented 3 years 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.

boojongmin commented 3 years ago

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