{"action":"created","issue":{"url":"https://api.github.com/repos/influxdb/influxdb/issues/4944","labels_url":"https://api.github.com/repos/influxdb/influxdb/issues/4944/labels{/name}","comments_url":"https://api.github.com/repos/influxdb/influxdb/issues/4944/comments","events_url":"https://api.github.com/repos/influxdb/influxdb/issues/4944/events","html_url":"https://github.com/influxdb/influxdb/issues/4944","id":119760047,"number":4944,"title":"desc modifier in order clause causes records to be omitted","user":{"login":"CVTJNII","id":13871930,"avatar_url":"https://avatars.githubusercontent.com/u/13871930?v=3","gravatar_id":"","url":"https://api.github.com/users/CVTJNII","html_url":"https://github.com/CVTJNII","followers_url":"https://api.github.com/users/CVTJNII/followers","following_url":"https://api.github.com/users/CVTJNII/following{/other_user}","gists_url":"https://api.github.com/users/CVTJNII/gists{/gist_id}","starred_url":"https://api.github.com/users/CVTJNII/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CVTJNII/subscriptions","organizations_url":"https://api.github.com/users/CVTJNII/orgs","repos_url":"https://api.github.com/users/CVTJNII/repos","events_url":"https://api.github.com/users/CVTJNII/events{/privacy}","received_events_url":"https://api.github.com/users/CVTJNII/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-12-01T16:53:13Z","updated_at":"2015-12-01T21:40:08Z","closed_at":"2015-12-01T20:23:36Z","body":"When sorting a query by time descending records are not returned.  Using a simple test script against a InfluxDB 0.9.4.2 instance which is being constantly updated:\r\n\r\n```\r\nCurrent time: 2015-12-01T16:48:01.586443Z\r\n'select time,value from \"riemann streams latency 0.95\" order by time desc' latest time: 2015-12-01T15:22:59.663Z\r\n'select time,value from \"riemann streams latency 0.95\" order by time' latest time: 2015-12-01T16:48:00.011Z\r\n'select time,value from \"riemann streams latency 0.95\"' latest time: 2015-12-01T16:48:00.011Z\r\n```\r\n\r\nNote that records for 16:48 were returned for the queries without the desc modifier, whereas with the desc modifier the latest time is 15:22: over an hour's worth of records are missing.  As the sort order is descending the latest records will be first, so this is not a pagination issue.\r\n\r\nThe above was generated with the following script, which does it's own time sort to ensure the latest row is printed on unordered queries:\r\n\r\n```python\r\n#!/usr/bin/python -tt\r\n\r\nimport argparse\r\nimport urllib\r\nimport urllib2\r\nimport json\r\nimport datetime\r\nimport sys\r\n\r\ndef parse_args():\r\n    \"\"\"Parse command line arguments\"\"\"\r\n    parser = argparse.ArgumentParser(description='Check age of InfluxDB points for a given measurement match', formatter_class=argparse.ArgumentDefaultsHelpFormatter)\r\n    \r\n    parser.add_argument('-H', '--host', action='store', default='172.17.42.1', help='InfluxDB Host', type=str)\r\n    parser.add_argument('-P', '--port', action='store', default='8086', help='InfluxDB Port', type=int)\r\n    parser.add_argument('-u', '--user', action='store', default=None, help='InfluxDB Username', type=str)\r\n    parser.add_argument('-p', '--passwd', action='store', default=None, help='InfluxDB Password', type=str)\r\n    parser.add_argument('-d', '--database', action='store', default='riemann', help='InfluxDB Database', type=str)\r\n\r\n    parser.add_argument('-m', '--measurement', action='store', default='/.*/', help='InfluxDB Measurement', type=str)\r\n\r\n    return parser.parse_args()\r\n\r\ndef run_query(args, query):\r\n    \"\"\"Run the influxDB query\"\"\"\r\n    # This uses urllib(2) instead of something like requests to avoid needing to install packages\r\n\r\n    # There are some injection vulnerabilities here... (TODO)\r\n    url_args = {'db': args.database,\r\n                'q': query\r\n                }\r\n    \r\n    if args.user is not None or args.passwd is not None:\r\n        url_args['u'] = args.user\r\n        url_args['p'] = args.passwd\r\n    \r\n    url = \"http://%s:%s/query?%s\" % (args.host, args.port, urllib.urlencode(url_args))\r\n    try:\r\n        api_raw_data = urllib2.urlopen(url).read()\r\n    except Exception as exc:\r\n        raise Exception(\"Unable to query InfluxDB: %s\" % str(exc))\r\n\r\n    try:\r\n        data = json.loads(api_raw_data)\r\n    except Exception as exc:\r\n        raise Exception(\"Unable to parse API response: %s\" % str(exc))\r\n\r\n    return data['results'][0]['series'][0]\r\n\r\ndef print_query(args, query):\r\n    resp = sorted(run_query(args, query)['values'], key = lambda r: r[0])\r\n    print \"'%s' latest time: %s\" % (query, resp[-1][0])\r\n\r\ndef main():\r\n    args = parse_args()\r\n\r\n    print \"Current time: %s\" % datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S.%fZ')\r\n#    print_query(args, (\"select time,value from %s order by time desc limit 1\" % args.measurement))\r\n    print_query(args, (\"select time,value from %s order by time desc\" % args.measurement))\r\n    print_query(args, (\"select time,value from %s order by time\" % args.measurement))\r\n    print_query(args, (\"select time,value from %s\" % args.measurement))\r\n#    print_query(args, (\"select last(value) from %s\" % args.measurement))\r\n\r\nif __name__ == '__main__':\r\n    sys.exit(main())\r\n```\r\n\r\nThe above was run with measurement set to a single series, however this behavior is seen against /.*/ as well."},"comment":{"url":"https://api.github.com/repos/influxdb/influxdb/issues/comments/161104031","html_url":"https://github.com/influxdb/influxdb/issues/4944#issuecomment-161104031","issue_url":"https://api.github.com/repos/influxdb/influxdb/issues/4944","id":161104031,"user":{"login":"CVTJNII","id":13871930,"avatar_url":"https://avatars.githubusercontent.com/u/13871930?v=3","gravatar_id":"","url":"https://api.github.com/users/CVTJNII","html_url":"https://github.com/CVTJNII","followers_url":"https://api.github.com/users/CVTJNII/followers","following_url":"https://api.github.com/users/CVTJNII/following{/other_user}","gists_url":"https://api.github.com/users/CVTJNII/gists{/gist_id}","starred_url":"https://api.github.com/users/CVTJNII/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CVTJNII/subscriptions","organizations_url":"https://api.github.com/users/CVTJNII/orgs","repos_url":"https://api.github.com/users/CVTJNII/repos","events_url":"https://api.github.com/users/CVTJNII/events{/privacy}","received_events_url":"https://api.github.com/users/CVTJNII/received_events","type":"User","site_admin":false},"created_at":"2015-12-01T21:40:08Z","updated_at":"2015-12-01T21:40:08Z","body":"Does the fix for this not work with existing data?  I don't see this on 0.9.5.1 in a sandbox with no existing data but I do see it after upgrading my prod hosts from 0.9.4.2."}}