[GH-ISSUE #117] Issue with index created on large set of existing dates #68

Closed
opened 2026-05-23 08:28:58 -06:00 by gitea-mirror · 5 comments
Owner

Originally created by @donl on GitHub (Jun 15, 2022).
Original GitHub issue: https://github.com/appy-one/acebase/issues/117

I seem to have an issue when creating an index on a large set of existing date values.

Hopefully the code below is helpful. Sorry for any bad practices :)

In some instances on subsequent executions (without deleting the db) I get an assertion error: Assertion failed: Node entries are not sorted ok


const { AceBase } = require("acebase");

const dbname = "idx-test";
const options = {logLevel: 'error'};

let db = {};

const main = async () => {

    db = new AceBase(dbname, options);
    await db.ready();

    // Works better if index is created first...
    // await db.indexes.create('item','at');

    const preCount = await db.ref('item').count();
    console.log('preCount',preCount);

    var currentDate = new Date('1/1/2000');
    var stopDate = new Date('12/31/2022');
    var dates = {};

    while (currentDate <= stopDate) {
        const ref = db.ref('item').push();
        dates[ref.key] = {at: new Date (currentDate)};

        let d = new Date(currentDate);
        currentDate = d.setDate(d.getDate()+1);
    }

    await db.ref('item').update(dates);

    const postCount = await db.ref('item').count();
    console.log('postCount',postCount);


    snaps = await db.query('item')
    .filter('at','between',[new Date('5/1/2022'), new Date('1/1/2022')])
    .get();
    console.log("query 1 length: ",snaps.getValues().length);


    // problem with index created on bulk existing data
    await db.indexes.create('item','at').then(()=>{
        console.log('index created...')
    });

    snaps = await db.query('item')
    .filter('at','between',[new Date('5/1/2022'), new Date('1/1/2022')])
    .get();
    console.log("query 2 length: ",snaps.getValues().length);
}

main();

Originally created by @donl on GitHub (Jun 15, 2022). Original GitHub issue: https://github.com/appy-one/acebase/issues/117 I seem to have an issue when creating an index on a large set of existing date values. Hopefully the code below is helpful. Sorry for any bad practices :) In some instances on subsequent executions (without deleting the db) I get an assertion error: `Assertion failed: Node entries are not sorted ok` ```js const { AceBase } = require("acebase"); const dbname = "idx-test"; const options = {logLevel: 'error'}; let db = {}; const main = async () => { db = new AceBase(dbname, options); await db.ready(); // Works better if index is created first... // await db.indexes.create('item','at'); const preCount = await db.ref('item').count(); console.log('preCount',preCount); var currentDate = new Date('1/1/2000'); var stopDate = new Date('12/31/2022'); var dates = {}; while (currentDate <= stopDate) { const ref = db.ref('item').push(); dates[ref.key] = {at: new Date (currentDate)}; let d = new Date(currentDate); currentDate = d.setDate(d.getDate()+1); } await db.ref('item').update(dates); const postCount = await db.ref('item').count(); console.log('postCount',postCount); snaps = await db.query('item') .filter('at','between',[new Date('5/1/2022'), new Date('1/1/2022')]) .get(); console.log("query 1 length: ",snaps.getValues().length); // problem with index created on bulk existing data await db.indexes.create('item','at').then(()=>{ console.log('index created...') }); snaps = await db.query('item') .filter('at','between',[new Date('5/1/2022'), new Date('1/1/2022')]) .get(); console.log("query 2 length: ",snaps.getValues().length); } main(); ```
Author
Owner

@appy-one commented on GitHub (Jun 16, 2022):

I worked quite a bit on the indexes lately. Can you check if you are using the latest version?

<!-- gh-comment-id:1157275406 --> @appy-one commented on GitHub (Jun 16, 2022): I worked quite a bit on the indexes lately. Can you check if you are using the latest version?
Author
Owner

@donl commented on GitHub (Jun 16, 2022):

Running 1.21.4

I see there is api.getServerInfo() that returns the server version. Is there a good way to get the AceBase and/or AceBase-client version?

<!-- gh-comment-id:1157346494 --> @donl commented on GitHub (Jun 16, 2022): Running `1.21.4` I see there is `api.getServerInfo()` that returns the server version. Is there a good way to get the AceBase and/or AceBase-client version?
Author
Owner

@appy-one commented on GitHub (Jun 16, 2022):

I'll investigate what's going wrong

<!-- gh-comment-id:1157887588 --> @appy-one commented on GitHub (Jun 16, 2022): I'll investigate what's going wrong
Author
Owner

@appy-one commented on GitHub (Jun 16, 2022):

I found the issue, published a fix in v1.21.5. Thanks for the great example code, that saved a lot of work!

<!-- gh-comment-id:1157948973 --> @appy-one commented on GitHub (Jun 16, 2022): I found the issue, published a fix in v1.21.5. Thanks for the great example code, that saved a lot of work!
Author
Owner

@appy-one commented on GitHub (Jun 16, 2022):

I see there is api.getServerInfo() that returns the server version. Is there a good way to get the AceBase and/or AceBase-client version?

Not yet, I'll implement that 👍🏼

<!-- gh-comment-id:1157949652 --> @appy-one commented on GitHub (Jun 16, 2022): > I see there is `api.getServerInfo()` that returns the server version. Is there a good way to get the AceBase and/or AceBase-client version? Not yet, I'll implement that 👍🏼
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/acebase#68
No description provided.