annotate caching-tests/test.ur @ 2291:50ad02829abd

Make cache flushes happen immediately instead of at end of transaction.
author Ziv Scully <ziv@mit.edu>
date Tue, 17 Nov 2015 02:44:37 -0500
parents b7615e0ac4b0
children f8903af753ff
rev   line source
ziv@2275 1 table tab : {Id : int, Val : int, Foo : int} PRIMARY KEY Id
ziv@2203 2
ziv@2213 3 fun cache id =
ziv@2225 4 res <- oneOrNoRows (SELECT tab.Val
ziv@2225 5 FROM tab
ziv@2225 6 WHERE tab.Id = {[id]});
ziv@2204 7 return <xml><body>
ziv@2278 8 cache
ziv@2276 9 {case res of
ziv@2276 10 None => <xml>?</xml>
ziv@2276 11 | Some row => <xml>{[row.Tab.Val]}</xml>}
ziv@2276 12 </body></xml>
ziv@2276 13
ziv@2278 14 fun sillyRecursive {Id = id : int, FooBar = fooBar} =
ziv@2278 15 if fooBar <= 0
ziv@2278 16 then 0
ziv@2278 17 else 1 + sillyRecursive {Id = id, FooBar = fooBar - 1}
ziv@2276 18
ziv@2276 19 fun cacheR (r : {Id : int, FooBar : int}) =
ziv@2276 20 res <- oneOrNoRows (SELECT tab.Val
ziv@2276 21 FROM tab
ziv@2276 22 WHERE tab.Id = {[r.Id]});
ziv@2276 23 return <xml><body>
ziv@2278 24 cacheR {[r.FooBar]}
ziv@2204 25 {case res of
ziv@2213 26 None => <xml>?</xml>
ziv@2213 27 | Some row => <xml>{[row.Tab.Val]}</xml>}
ziv@2204 28 </body></xml>
ziv@2203 29
ziv@2273 30 (* fun cache2 id v = *)
ziv@2273 31 (* res <- oneOrNoRows (SELECT tab.Val *)
ziv@2273 32 (* FROM tab *)
ziv@2273 33 (* WHERE tab.Id = {[id]} AND tab.Val = {[v]}); *)
ziv@2273 34 (* return <xml><body> *)
ziv@2273 35 (* Reading {[id]}. *)
ziv@2273 36 (* {case res of *)
ziv@2273 37 (* None => <xml>Nope, that's not it.</xml> *)
ziv@2273 38 (* | Some _ => <xml>Hooray! You guessed it!</xml>} *)
ziv@2273 39 (* </body></xml> *)
ziv@2273 40
ziv@2275 41 (* fun cache2 id1 id2 = *)
ziv@2275 42 (* res1 <- oneOrNoRows (SELECT tab.Val *)
ziv@2275 43 (* FROM tab *)
ziv@2275 44 (* WHERE tab.Id = {[id1]}); *)
ziv@2275 45 (* res2 <- oneOrNoRows (SELECT tab.Val *)
ziv@2275 46 (* FROM tab *)
ziv@2275 47 (* WHERE tab.Id = {[id2]}); *)
ziv@2275 48 (* return <xml><body> *)
ziv@2275 49 (* Reading {[id1]} and {[id2]}. *)
ziv@2275 50 (* {case (res1, res2) of *)
ziv@2275 51 (* (Some _, Some _) => <xml>Both are there.</xml> *)
ziv@2275 52 (* | _ => <xml>One of them is missing.</xml>} *)
ziv@2275 53 (* </body></xml> *)
ziv@2269 54
ziv@2213 55 fun flush id =
ziv@2239 56 dml (UPDATE tab
ziv@2239 57 SET Val = Val * (Id + 2) / Val - 3
ziv@2239 58 WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]});
ziv@2204 59 return <xml><body>
ziv@2235 60 Changed {[id]}!
ziv@2204 61 </body></xml>
ziv@2234 62
ziv@2275 63 fun flash id =
ziv@2242 64 dml (UPDATE tab
ziv@2275 65 SET Foo = Val
ziv@2275 66 WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]});
ziv@2242 67 return <xml><body>
ziv@2275 68 Maybe changed {[id]}?
ziv@2242 69 </body></xml>
ziv@2242 70
ziv@2275 71 fun floosh id =
ziv@2275 72 dml (UPDATE tab
ziv@2275 73 SET Id = {[id + 1]}
ziv@2275 74 WHERE Id = {[id]});
ziv@2275 75 return <xml><body>
ziv@2275 76 Shifted {[id]}!
ziv@2275 77 </body></xml>
ziv@2275 78
ziv@2275 79 (* val flush17 = *)
ziv@2275 80 (* dml (UPDATE tab *)
ziv@2275 81 (* SET Val = Val * (Id + 2) / Val - 3 *)
ziv@2275 82 (* WHERE Id = 17); *)
ziv@2275 83 (* return <xml><body> *)
ziv@2275 84 (* Changed specifically 17! *)
ziv@2275 85 (* </body></xml> *)
ziv@2275 86
ziv@2235 87 (* fun flush id = *)
ziv@2235 88 (* res <- oneOrNoRows (SELECT tab.Val *)
ziv@2235 89 (* FROM tab *)
ziv@2235 90 (* WHERE tab.Id = {[id]}); *)
ziv@2235 91 (* (case res of *)
ziv@2235 92 (* None => dml (INSERT INTO tab (Id, Val) *)
ziv@2235 93 (* VALUES ({[id]}, 0)) *)
ziv@2235 94 (* | Some row => dml (UPDATE tab *)
ziv@2235 95 (* SET Val = {[row.Tab.Val + 1]} *)
ziv@2235 96 (* WHERE Id = {[id]} OR Id = {[id + 1]})); *)
ziv@2235 97 (* return <xml><body> *)
ziv@2235 98 (* {case res of *)
ziv@2235 99 (* None => <xml>Initialized {[id]}!</xml> *)
ziv@2235 100 (* | Some row => <xml>Incremented {[id]}!</xml>} *)
ziv@2235 101 (* </body></xml> *)