Details
-
Bug
-
Status: Resolved
-
Critical
-
Resolution: Fixed
-
None
-
None
-
None
-
Mac and latest open source *DB snapshot
Description
Consider the following index (created as part of the repro scenario below):
CREATE INDEX gbUserSinceIdx2 ON GleambookUsers(userSince: int?);
Here are several queries that tickle the index (and its friends in the setup below) in various ways:
SELECT VALUE user
FROM GleambookUsers user
WHERE user.userSince >= datetime('2010-07-22T00:00:00')
AND user.userSince <= datetime('2012-07-29T23:59:59');
SELECT VALUE user
FROM GleambookUsers user
WHERE user.userSince = "yesterday";
SELECT VALUE user
FROM GleambookUsers user
WHERE user.userSince > 900;
The first two work fine, but the last one should return:
{ "id": 777, "alias": "Hillery", "name": "HillaryClinton", "userSince": 1000 }but it doesn't if the above index is present. (It does fine w/o the index.) You can see this by running the following:
SELECT VALUE user
FROM GleambookUsers user
WHERE user.userSince > 900;
DROP INDEX GleambookUsers.gbUserSinceIdx2;
SELECT VALUE user
FROM GleambookUsers user
WHERE user.userSince > 900;
-------------------------------------------------------------------------------------------
HERE'S A BIG HINT: If the CREATE INDEX statements happen before the INSERT statements, the bug appears. If they are done AFTER the INSERT statements, the correct answer is produced. This leads me to believe that the bug is on the INSERT path - it's not the SELECT query that's the problem, it's the INSERT of the data. (I.e., LOAD works, INSERT doesn't work?) Just a hunch.
-------------------------------------------------------------------------------------------
Here's my little test data setup (adapted from the SQL++ Primer) for repro purposes - cut and paste from here to see the problem.
DROP DATAVERSE TinySocial IF EXISTS;
CREATE DATAVERSE TinySocial;
USE TinySocial;
CREATE TYPE ChirpUserType AS {
screenName: string
};
CREATE TYPE ChirpMessageType AS {
chirpId: string
};
CREATE TYPE GleambookUserType AS {
id: int
};
CREATE TYPE GleambookMessageType AS {
messageId: int
};
CREATE DATASET GleambookUsers(GleambookUserType)
PRIMARY KEY id;
CREATE DATASET GleambookMessages(GleambookMessageType)
PRIMARY KEY messageId;
CREATE DATASET ChirpUsers(ChirpUserType)
PRIMARY KEY screenName;
CREATE DATASET ChirpMessages(ChirpMessageType)
PRIMARY KEY chirpId;
CREATE INDEX gbUserSinceIdx ON GleambookUsers(userSince: datetime?);
CREATE INDEX gbUserSinceIdx2 ON GleambookUsers(userSince: int?);
CREATE INDEX gbAuthorIdx ON GleambookMessages(authorId: int?) TYPE btree;
INSERT INTO ChirpUsers
([
,
,
,
{"screenName":"ChangEwing_573","lang":"en","friendsCount":182,"statusesCount":394,"name":"Chang Ewing","followersCount":32136}]);
INSERT INTO ChirpMessages
([
{"chirpId":"1","user":
,"senderLocation":point("47.44,80.65"),"sendTime":datetime("2008-04-26T10:10:00"),"referredTopics":"product-z","customization","messageText":" love product-z its customization is good"},
{"chirpId":"2","user":
,"senderLocation":point("32.84,67.14"),"sendTime":datetime("2010-05-13T10:10:00"),"referredTopics":"ccast","shortcut-menu","messageText":" like ccast its shortcut-menu is awesome"},
{"chirpId":"3","user":
,"senderLocation":point("29.72,75.8"),"sendTime":datetime("2006-11-04T10:10:00"),"referredTopics":"product-w","speed","messageText":" like product-w the speed is good"},
{"chirpId":"4","user":
,"senderLocation":point("39.28,70.48"),"sendTime":datetime("2011-12-26T10:10:00"),"referredTopics":"product-b","voice-command","messageText":" like product-b the voice-command is mind-blowing"},
{"chirpId":"5","user":
,"senderLocation":point("40.09,92.69"),"sendTime":datetime("2006-08-04T10:10:00"),"referredTopics":"product-w","speed","messageText":" can't stand product-w its speed is terrible"},
{"chirpId":"6","user":
,"senderLocation":point("47.51,83.99"),"sendTime":datetime("2010-05-07T10:10:00"),"referredTopics":"x-phone","voice-clarity","messageText":" like x-phone the voice-clarity is good"},
{"chirpId":"7","user":
,"senderLocation":point("36.21,72.6"),"sendTime":datetime("2011-08-25T10:10:00"),"referredTopics":"product-y","platform","messageText":" like product-y the platform is good"},
{"chirpId":"8","user":
,"senderLocation":point("46.05,93.34"),"sendTime":datetime("2005-10-14T10:10:00"),"referredTopics":"product-z","shortcut-menu","messageText":" like product-z the shortcut-menu is awesome"},
{"chirpId":"9","user":
,"senderLocation":point("36.86,74.62"),"sendTime":datetime("2012-07-21T10:10:00"),"referredTopics":"ccast","voicemail-service","messageText":" love ccast its voicemail-service is awesome"},
{"chirpId":"10","user":
,"senderLocation":point("29.15,76.53"),"sendTime":datetime("2008-01-26T10:10:00"),"referredTopics":"ccast","voice-clarity","messageText":" hate ccast its voice-clarity is OMG"},
{"chirpId":"11","user":
,"senderLocation":point("37.59,68.42"),"sendTime":datetime("2008-03-09T10:10:00"),"referredTopics":"x-phone","platform","messageText":" can't stand x-phone its platform is terrible"},
{"chirpId":"12","user":
,"senderLocation":point("24.82,94.63"),"sendTime":datetime("2010-02-13T10:10:00"),"referredTopics":"product-y","voice-command","messageText":" like product-y the voice-command is amazing"}
]);
INSERT INTO GleambookUsers
([
{"id":1,"alias":"Margarita","name":"MargaritaStoddard","nickname":"Mags","userSince":datetime("2012-08-20T10:10:00"),"friendIds":2,3,6,10,"employment":[
,
{"organizationName":"geomedia","startDate":date("2010-06-17"),"endDate":date("2010-01-26")}],"gender":"F"},
{"id":2,"alias":"Isbel","name":"IsbelDull","nickname":"Izzy","userSince":datetime("2011-01-22T10:10:00"),"friendIds":1,4,"employment":[
]},
{"id":3,"alias":"Emory","name":"EmoryUnk","userSince":datetime("2012-07-10T10:10:00"),"friendIds":1,5,8,9,"employment":[
]},
{"id":4,"alias":"Nicholas","name":"NicholasStroh","userSince":datetime("2010-12-27T10:10:00"),"friendIds":2,"employment":[
]},
{"id":5,"alias":"Von","name":"VonKemble","userSince":datetime("2010-01-05T10:10:00"),"friendIds":3,6,10,"employment":[
]},
{"id":6,"alias":"Willis","name":"WillisWynne","userSince":datetime("2005-01-17T10:10:00"),"friendIds":1,3,7,"employment":[
]},
{"id":7,"alias":"Suzanna","name":"SuzannaTillson","userSince":datetime("2012-08-07T10:10:00"),"friendIds":6,"employment":[
]},
{"id":8,"alias":"Nila","name":"NilaMilliron","userSince":datetime("2008-01-01T10:10:00"),"friendIds":3,"employment":[
]},
{"id":9,"alias":"Woodrow","name":"WoodrowNehling","nickname":"Woody","userSince":datetime("2005-09-20T10:10:00"),"friendIds":3,10,"employment":[
]},
{"id":10,"alias":"Bram","name":"BramHatch","userSince":datetime("2010-10-16T10:10:00"),"friendIds":1,5,9,"employment":[
]},
,
{"id":777,"alias":"Hillery","name":"HillaryClinton","userSince":1000}]);
INSERT INTO GleambookMessages
([
,
,
,
,
,
,
,
,
,
,
,
,
,
,
{"messageId":15,"authorId":7,"inResponseTo":11,"senderLocation":point("44.47,67.11"),"message":" like x-phone the voicemail-service is awesome"}]);
SELECT VALUE user
FROM GleambookUsers user
WHERE user.userSince >= datetime('2010-07-22T00:00:00')
AND user.userSince <= datetime('2012-07-29T23:59:59');
SELECT VALUE user
FROM GleambookUsers user
WHERE user.userSince = "yesterday";
SELECT VALUE user
FROM GleambookUsers user
WHERE user.userSince > 900;