diff src/monoize.sml @ 255:69d337f186eb

Monoized GROUP BY
author Adam Chlipala <adamc@hcoop.net>
date Sun, 31 Aug 2008 15:04:10 -0400
parents f8d9395575ec
children 40c33706d887
line wrap: on
line diff
--- a/src/monoize.sml	Sun Aug 31 14:33:22 2008 -0400
+++ b/src/monoize.sml	Sun Aug 31 15:04:10 2008 -0400
@@ -614,7 +614,24 @@
                                            strcatComma loc (map (fn (x, _) => strcat loc [(L'.EField (gf "From", x), loc),
                                                                                           sc (" AS " ^ x)]) tables),
                                            sc " WHERE ",
-                                           gf "Where"
+                                           gf "Where",
+                                           if List.all (fn (x, xts) =>
+                                                           case List.find (fn (x', _) => x' = x) grouped of
+                                                               NONE => List.null xts
+                                                             | SOME (_, xts') =>
+                                                               List.all (fn (x, _) =>
+                                                                            List.exists (fn (x', _) => x' = x)
+                                                                                        xts') xts) tables then
+                                               sc ""
+                                           else
+                                               strcat loc [
+                                               sc " GROUP BY ",
+                                               strcatComma loc (map (fn (x, xts) =>
+                                                                        strcatComma loc
+                                                                                    (map (fn (x', _) =>
+                                                                                             sc (x ^ "." ^ x'))
+                                                                                         xts)) grouped)
+                                               ]
                               ]), loc),
                      fm)
                   | _ => poly ()