[GH-ISSUE #15] Incorrect query results #13

Closed
opened 2026-05-23 08:25:22 -06:00 by gitea-mirror · 3 comments
Owner

Originally created by @clibu on GitHub (Mar 3, 2021).
Original GitHub issue: https://github.com/appy-one/acebase/issues/15

Originally assigned to: @appy-one on GitHub.

I have a db with the following content:

songs: {
  klpmmym80000ggkkuzd3dtg1: {
    title: 'life on the Edge',
    artist: 'John Mayer',
    year: 2014,
    genre: 'pop',
    sex: 'none'
  },
  klpmqzur0000vgkkpn0g4uho: {
    title: 'Daughters',
    artist: 'John Mayer',
    year: 2014,
    genre: 'pop'
  },
  klpmtqrx0000xokkvim8n26w: {
    title: 'Crazy',
    artist: 'Gnarls Barkley',
    year: 2012,
    genre: 'rock'
  },
  klppvq780000hkkkvwdt4saf: {
    title: 'Lovely Sky',
    artist: 'Martha Smith',
    year: 2012,
    genre: 'folk'
  },
  klppvq7a0001hkkkgc27oea1: {
    title: 'Skylark',
    artist: 'Macey Grey',
    year: 2014,
    genre: 'pop'
  }
}

And these indexes:

db.indexes.create('songs', 'year')
db.indexes.create('songs', 'genre')
db.indexes.create('songs', 'year', { include: ['genre'] })

When I run this query:

db.query( 'songs' )
        .filter( 'year', '>=', 2012 )
        .filter( 'genre', 'in', ['jazz','rock','blues'])
        .sort( 'title' )
        .get()

I get 5 songs:

snapshot.val: { title: 'Crazy', artist: 'Gnarls Barkley', year: 2012, genre: 'rock' }
snapshot.val: { title: 'Daughters', artist: 'John Mayer', year: 2014, genre: 'pop' }
snapshot.val: { title: 'Lovely Sky',  artist: 'Martha Smith',  year: 2012,  genre: 'folk'}
snapshot.val: { title: 'Skylark', artist: 'Macey Grey', year: 2014, genre: 'pop' }
snapshot.val: {  title: 'life on the Edge',  artist: 'John Mayer',  year: 2014,  genre: 'pop',  sex: 'none'}

When only the first one should match. If I do this without the last (composite) index I get the correct results.

It may well be that this combination of indexes is invalid or doesn't make sense!

Originally created by @clibu on GitHub (Mar 3, 2021). Original GitHub issue: https://github.com/appy-one/acebase/issues/15 Originally assigned to: @appy-one on GitHub. I have a db with the following content: ```` songs: { klpmmym80000ggkkuzd3dtg1: { title: 'life on the Edge', artist: 'John Mayer', year: 2014, genre: 'pop', sex: 'none' }, klpmqzur0000vgkkpn0g4uho: { title: 'Daughters', artist: 'John Mayer', year: 2014, genre: 'pop' }, klpmtqrx0000xokkvim8n26w: { title: 'Crazy', artist: 'Gnarls Barkley', year: 2012, genre: 'rock' }, klppvq780000hkkkvwdt4saf: { title: 'Lovely Sky', artist: 'Martha Smith', year: 2012, genre: 'folk' }, klppvq7a0001hkkkgc27oea1: { title: 'Skylark', artist: 'Macey Grey', year: 2014, genre: 'pop' } } ```` And these indexes: ```` db.indexes.create('songs', 'year') db.indexes.create('songs', 'genre') db.indexes.create('songs', 'year', { include: ['genre'] }) ```` When I run this query: ```` db.query( 'songs' ) .filter( 'year', '>=', 2012 ) .filter( 'genre', 'in', ['jazz','rock','blues']) .sort( 'title' ) .get() ```` I get 5 songs: ```` snapshot.val: { title: 'Crazy', artist: 'Gnarls Barkley', year: 2012, genre: 'rock' } snapshot.val: { title: 'Daughters', artist: 'John Mayer', year: 2014, genre: 'pop' } snapshot.val: { title: 'Lovely Sky', artist: 'Martha Smith', year: 2012, genre: 'folk'} snapshot.val: { title: 'Skylark', artist: 'Macey Grey', year: 2014, genre: 'pop' } snapshot.val: { title: 'life on the Edge', artist: 'John Mayer', year: 2014, genre: 'pop', sex: 'none'} ```` When only the first one should match. If I do this without the last _(composite)_ index I get the correct results. It may well be that this combination of indexes is invalid or doesn't make sense!
gitea-mirror 2026-05-23 08:25:22 -06:00
Author
Owner

@appy-one commented on GitHub (Mar 3, 2021):

It should only use the last index for that query because it has both year and genre. I'll have a look what's going on there.

<!-- gh-comment-id:789551177 --> @appy-one commented on GitHub (Mar 3, 2021): It should only use the last index for that query because it has both year and genre. I'll have a look what's going on there.
Author
Owner

@appy-one commented on GitHub (Mar 3, 2021):

Fix published in v1.1.2

<!-- gh-comment-id:789669841 --> @appy-one commented on GitHub (Mar 3, 2021): Fix published in v1.1.2
Author
Owner

@clibu commented on GitHub (Mar 4, 2021):

@appy-one All good now. Thanks.

<!-- gh-comment-id:790387304 --> @clibu commented on GitHub (Mar 4, 2021): @appy-one All good now. Thanks.
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#13
No description provided.