Skip to content

Commit

Permalink
fixed sub optimized query issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Lott authored and Scott Lott committed Oct 10, 2018
1 parent 86cdfc2 commit a97475d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
20 changes: 0 additions & 20 deletions examples/index.html
Expand Up @@ -10,26 +10,6 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.min.js"></script>
<script>

nSQL("message")
.model([{
key: "id",
type: "string",
props: ["pk", "ai"]
},
{
key: "message",
type: "string"
}
]).connect().then(() => {
return nSQL("message").query("upsert", {
id: "",
message: ""
}).exec();
}).then(() => {
console.log("HEY");
}).catch((err) => {
console.error(err);
})
/*nSQL("message")
.model([
{ key: "id", type: "int", props: ["pk", "ai"] },
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/database/query.ts
Expand Up @@ -1619,6 +1619,8 @@ export class _RowSelection {
}, 0) === 0;
}



if (doFastRead) { // can go straight to primary or secondary keys, wee!
this._selectByKeysOrSeach(this.q.where, callback);
return;
Expand All @@ -1627,9 +1629,11 @@ export class _RowSelection {
// if compound where statement includes primary key/secondary index queries followed by AND with other conditions.
// grabs the section of data related to the optimized read, then full table scans the result.
const whereSlice = this._isSubOptimizedWhere(this.q.where);

if (whereSlice > 0) {
const fastWhere: any[] = this.q.where.slice(0, whereSlice);
const slowWhere: any[] = this.q.where.slice(whereSlice + 1);
console.log(fastWhere, slowWhere);
this._selectByKeysOrSeach(fastWhere, (rows) => {
callback(rows.filter((r, i) => _where(r, slowWhere, i, false)));
});
Expand Down Expand Up @@ -2316,7 +2320,7 @@ export class _RowSelection {
const wCondition = wArgs[1] || "";

if (Array.isArray(wQuery)) { // nested where statement
return 0;
return 1;
}

// is a valid crow query with secondary indexes
Expand Down

0 comments on commit a97475d

Please sign in to comment.