I am attempting to perform a query using timeuuid to retrieve a result set.
Table is as such:
CREATE TABLE mds.arguments_by_id (
argument_id timeuuid PRIMARY KEY,
category text,
title text
)
When I select the dateOf() for all of the data in the table, I get the following:
select dateOf(argument_id),argument_id from arguments_by_id ;
dateOf(argument_id) | argument_id
-------------------------+--------------------------------------
2014-12-29 13:50:07-0500 | 81f990c0-8f8b-11e4-abb3-5d7a44c0d8a8
2014-12-29 14:01:43-0500 | 20def1c0-8f8d-11e4-abb3-5d7a44c0d8a8
2014-12-29 14:01:58-0500 | 29b50f50-8f8d-11e4-abb3-5d7a44c0d8a8
2014-12-29 14:03:01-0500 | 4f6b72c0-8f8d-11e4-bc90-abc65998337a
(4 rows)
The query I'd like to run needs to return results where the argument_id (date) is greater than a specified date:
select dateOf(argument_id),argument_id from arguments_by_id where token(argument_id) > token(maxTimeuuid('2014-12-28 15:31:00-0500'));
However that query returns a (seemingly) incomplete result set when compared to the previous select:
dateOf(argument_id) | argument_id
--------------------------+--------------------------------------
2014-12-29 14:01:43-0500 | 20def1c0-8f8d-11e4-abb3-5d7a44c0d8a8
2014-12-29 14:01:58-0500 | 29b50f50-8f8d-11e4-abb3-5d7a44c0d8a8
2014-12-29 14:03:01-0500 | 4f6b72c0-8f8d-11e4-bc90-abc65998337a
(3 rows)
My goal was to minimize the number of keys - but am wondering if I am 1) incurring a performance hit by going this route and 2) trying to do too much with the primary key.
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
SELECT
dateOf(arguments_by_id.argument_id),
arguments_by_id.argument_id
FROM
arguments_by_id
WHERE
token(arguments_by_id.argument_id) > token(maxTimeuuid('2014-12-28 15:31:00-0500'))