Fork me on GitHub
#datomic
<
2017-11-17
>
zignd11:11:46

SQL Server offers a pagination syntax like so:

SELECT col1, col2, ...
 FROM ...
 WHERE ... 
 ORDER BY -- this is a MUST there must be ORDER BY statement
-- the paging comes here
OFFSET     10 ROWS       -- skip 10 rows
FETCH NEXT 10 ROWS ONLY; -- take 10 rows
is there something similar for queries in Datomic for pagination? or is it something like sorting and i would have to do outside the query?

augustl11:11:10

pagination is generally less useful when you have the data in your peer already anyway

augustl11:11:24

(take 10 result) 🙂

zignd11:11:01

oh i see then, it's like sorting

zignd11:11:25

but what people usually do when they have queries that return too much data? it would stay in memory for a moment because you're paginating after the query execution

augustl11:11:01

that's generally difficult to avoid. That would have to happen on a database server too

zignd11:11:45

you're right. the first thing i can think of would be to perform a query that retrieves the ids, then i'd paginate the ids and use them on a second query, that would retrieve the expected result using something like min max

augustl11:11:34

the only optimization I could think of is if you wanted to paginate without sorting, i.e. in whatever order the peer walks the index

augustl11:11:59

maybe just retrieving the IDs could work, yeah. Unless they're just stored in the same chunks as most of the data anyway

augustl11:11:28

my mental model of the organization of data in the cunks is lacking, so not sure if doing ids first would help...

zignd11:11:28

i'm not sure, either. because if the pagination depends on some sort of ordering this resolution model wouldn't be that great, in the first query i'd have to retrieve the ids and the other attributes required for the sorting before the pagination

augustl11:11:58

the attribuets you sort on are probably indexed I suppose? Then I would assume that the data are mostly in the same chunks in avet anyway

augustl11:11:21

or, wait. Does each index have its own set of chunks? Then at least you'd only have the indexed attributes in avet. I think?

augustl11:11:40

avet only contains the actual data that is indexed, I suppose? And if you need additional facts, you'd need to look it up in eavt or elsewhere

augustl11:11:56

"you" being the query engine

zignd11:11:13

oh, i didn't know there was indexes in Datomic, just checked the docs and there's a page on that, I guess I'll have to study xD

augustl11:11:54

you typically want to tag attributes you query for as indexed

zignd11:11:33

oh, i will keep that in mind

zignd11:11:31

doing so would affect the query results so that ordering would be done over the tagged attribute?

zignd11:11:28

reading the docs

augustl11:11:07

sort of kind of

augustl11:11:33

the indices started making sense to me after I started to play with the "datoms" API, that gives you direct access to the indices

augustl11:11:40

i.e. what the query engine ends up doing

augustl11:11:48

each index is a nested sorted set of data, nested differently. Or something like that. So "eavt" lets you input an e (entity id ) and get all attributes for that entity. Then you add an a and you get all values for that attribute. Then you walk those to find the attribute closest to the T of the db you're accessing

augustl11:11:18

and avet is just a different pattern, and only indexed values are stored there. So you add an attribute and you get all values for that attribute. And so on

zignd12:11:13

thanks for the help @augustl, that shed me a light

zignd12:11:44

it seems that the datoms API might be of some one, but I will have to experiment with it first