summaryrefslogtreecommitdiff
path: root/tcejdb
diff options
context:
space:
mode:
authoradam <adamansky@gmail.com>2012-11-14 23:37:00 +0700
committeradam <adamansky@gmail.com>2012-11-14 23:37:00 +0700
commitf8a990376f761ba31e4286527e52b77e381ac156 (patch)
treec2b8285134ff7125bcfa2dd730f84c04b77f35dc /tcejdb
parentc6e024134adb08f1e713cbe9c8b0f448ccfa1278 (diff)
downloadejdb-f8a990376f761ba31e4286527e52b77e381ac156.tar.gz
ejdb-f8a990376f761ba31e4286527e52b77e381ac156.tar.bz2
ejdb-f8a990376f761ba31e4286527e52b77e381ac156.zip
#7
Diffstat (limited to 'tcejdb')
-rw-r--r--tcejdb/ejdb.c106
-rw-r--r--tcejdb/testejdb/t2.c8
2 files changed, 84 insertions, 30 deletions
diff --git a/tcejdb/ejdb.c b/tcejdb/ejdb.c
index d686b6f..6762be5 100644
--- a/tcejdb/ejdb.c
+++ b/tcejdb/ejdb.c
@@ -1522,37 +1522,89 @@ static TCLIST* _qrysearch(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int q
if (mqf->flags & EJFPKMATCHING) { //PK matching
if (log) {
- tcxstrprintf(log, "PRIMARY KEY MATCHING: %s\n", mqf->expr);
+ tcxstrprintf(log, "PRIMARY KEY MATCHING: TRUE\n");
}
assert(mqf->expr);
- do {
- bson_oid_t oid;
- bson_oid_from_string(&oid, mqf->expr);
- void *cdata = tchdbget(jcoll->tdb->hdb, &oid, sizeof (oid), &bsbufsz);
- if (!cdata || !bsbufsz) {
- break;
- }
- bsbuf = tcmaploadone(cdata, bsbufsz, JDBCOLBSON, JDBCOLBSONL, &bsbufsz);
- if (!bsbuf || bsbufsz <= 4) {
+ if (mqf->tcop == TDBQCSTREQ) {
+ do {
+ bson_oid_t oid;
+ bson_oid_from_string(&oid, mqf->expr);
+ void *cdata = tchdbget(jcoll->tdb->hdb, &oid, sizeof (oid), &bsbufsz);
+ if (!cdata) {
+ break;
+ }
+ bsbuf = tcmaploadone(cdata, bsbufsz, JDBCOLBSON, JDBCOLBSONL, &bsbufsz);
+ if (!bsbuf) {
+ TCFREE(cdata);
+ break;
+ }
+ bool matched = true;
+ for (int i = 0; i < qfsz; ++i) {
+ const EJQF *qf = qfs[i];
+ if (qf->flags & EJFEXCLUDED) continue;
+ if (!_qrybsmatch(qf, bsbuf, bsbufsz)) {
+ matched = false;
+ break;
+ }
+ }
+ if (matched && (ejq->orqobjsnum == 0 || _qryormatch(jcoll, ejq, &oid, sizeof (oid), bsbuf, bsbufsz))) {
+ JBQREGREC(bsbuf, bsbufsz);
+ } else {
+ TCFREE(bsbuf);
+ }
TCFREE(cdata);
- break;
+ } while (false);
+ } else if (mqf->tcop == TDBQCSTROREQ) {
+ TCLIST *tokens = mqf->exprlist;
+ assert(tokens);
+ tclistsort(tokens);
+ for (int i = 1; i < TCLISTNUM(tokens); i++) {
+ if (!strcmp(TCLISTVALPTR(tokens, i), TCLISTVALPTR(tokens, i - 1))) {
+ TCFREE(tclistremove2(tokens, i));
+ i--;
+ }
}
- bool matched = true;
- for (int i = 0; i < qfsz; ++i) {
- const EJQF *qf = qfs[i];
- if (qf->flags & EJFEXCLUDED) continue;
- if (!_qrybsmatch(qf, bsbuf, bsbufsz)) {
- matched = false;
+ if (mqf->order < 0 && (mqf->flags & EJFORDERUSED)) {
+ tclistinvert(tokens);
+ }
+ int tnum = TCLISTNUM(tokens);
+ for (int i = 0; (all || count < max) && i < tnum; i++) {
+ const char *token;
+ int tsiz;
+ TCLISTVAL(token, tokens, i, tsiz);
+ if (tsiz < 1) {
+ continue;
+ }
+ bson_oid_t oid;
+ bson_oid_from_string(&oid, token);
+ void *cdata = tchdbget(jcoll->tdb->hdb, &oid, sizeof (oid), &bsbufsz);
+ if (!cdata) {
+ continue;
+ }
+ bsbuf = tcmaploadone(cdata, bsbufsz, JDBCOLBSON, JDBCOLBSONL, &bsbufsz);
+ if (!bsbuf) {
+ TCFREE(cdata);
break;
}
+ bool matched = true;
+ for (int i = 0; i < qfsz; ++i) {
+ const EJQF *qf = qfs[i];
+ if (qf->flags & EJFEXCLUDED) continue;
+ if (!_qrybsmatch(qf, bsbuf, bsbufsz)) {
+ matched = false;
+ break;
+ }
+ }
+ if (matched && (ejq->orqobjsnum == 0 || _qryormatch(jcoll, ejq, &oid, sizeof (oid), bsbuf, bsbufsz))) {
+ JBQREGREC(bsbuf, bsbufsz);
+ } else {
+ TCFREE(bsbuf);
+ }
+ TCFREE(cdata);
}
- if (matched && (ejq->orqobjsnum == 0 || _qryormatch(jcoll, ejq, &oid, sizeof (oid), bsbuf, bsbufsz))) {
- JBQREGREC(bsbuf, bsbufsz);
- } else {
- TCFREE(bsbuf);
- }
- TCFREE(cdata);
- } while (false);
+ } else {
+ assert(0);
+ }
} else if (mqf->tcop == TDBQTRUE) {
BDBCUR *cur = tcbdbcurnew(midx->db);
if (mqf->order >= 0) {
@@ -2114,7 +2166,8 @@ static void _qrypreprocess(EJCOLL *jcoll, EJQ *ejq, EJQF **mqf) {
assert(mvalsz == sizeof (EJQF));
assert(qf->fpath);
- if (qf->ftype == BSON_OID && qf->tcop == TDBQCSTREQ && !strcmp(JDBIDKEYNAME, qf->fpath)) { //OID PK matching
+ if ((qf->tcop == TDBQCSTREQ || qf->tcop == TDBQCSTROREQ) &&
+ !strcmp(JDBIDKEYNAME, qf->fpath)) { //OID PK matching
qf->flags |= EJFPKMATCHING;
*mqf = qf;
break;
@@ -2550,9 +2603,6 @@ static int _parse_qobj_impl(EJDB *jb, bson_iterator *it, TCMAP *qmap, TCLIST *pa
{
bson_iterator sit;
bson_iterator_subiterator(it, &sit);
- if (isckey) {
-
- }
ret = _parse_qobj_impl(jb, &sit, qmap, pathStack, &qf);
break;
}
diff --git a/tcejdb/testejdb/t2.c b/tcejdb/testejdb/t2.c
index 241478e..a2b894c 100644
--- a/tcejdb/testejdb/t2.c
+++ b/tcejdb/testejdb/t2.c
@@ -2616,8 +2616,6 @@ void testTicket7() { //https://github.com/Softmotions/ejdb/issues/7
CU_ASSERT_PTR_NOT_NULL_FATAL(bsdata);
}
//Now perform $in qry
-
-
//{_id : {$in : ["oid1", "oid2", "oid3"]}}
bson bsq2;
bson_init_as_query(&bsq2);
@@ -2650,6 +2648,12 @@ void testTicket7() { //https://github.com/Softmotions/ejdb/issues/7
TCXSTR *log2 = tcxstrnew();
TCLIST *q2res = ejdbqrysearch(coll, q2, &count2, 0, log2);
//fprintf(stderr, "\n%s", TCXSTRPTR(log2));
+ CU_ASSERT_TRUE(count2 == 3);
+ CU_ASSERT_PTR_NOT_NULL(strstr(TCXSTRPTR(log2), "MAIN IDX: 'NONE'"));
+ CU_ASSERT_PTR_NOT_NULL(strstr(TCXSTRPTR(log2), "PRIMARY KEY MATCHING: TRUE"));
+ CU_ASSERT_PTR_NOT_NULL(strstr(TCXSTRPTR(log2), "RS COUNT: 3"));
+
+ //TODO ID comparison
bson_destroy(&bsq1);
tclistdel(q1res);