]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/mathql_interpreter/use.ml
faster database format implemented
[helm.git] / helm / ocaml / mathql_interpreter / use.ml
index 899a2bf8923ff9d264f4625a7364e6b51da2bb54..7755ff20a78a14a60c05383761d10a6fa2bd37d2 100644 (file)
@@ -45,70 +45,42 @@ open Dbconn;;
  *                           comando USE/USED BY
  *)
 let use_ex alist asvar usek =
- let c = pgc () in
-  List.fold_left
-   (fun parziale xres ->
-    let r1 = helm_property_id usek
-    and r2 = helm_property_id "position"
-    and r3 = helm_property_id "occurrence"
-    in
-     let qq = "select distinct t" ^ r3 ^ ".att1, t" ^ r2 ^ ".att1 " ^
-      "from t" ^ r3 ^ ", t" ^ r2 ^ ", t" ^ r1 ^ " " ^
-      "where " ^ "t" ^ r1 ^ ".att0 = '" ^ (List.hd xres) ^ "' and t" ^ r1 ^
-      ".att1 = t" ^ r2 ^ ".att0 and t" ^ r1 ^ ".att1 = t" ^ r3 ^
-      ".att0 order by t" ^ r3 ^ ".att1 asc"
+ let _ = print_string ("USE ")
+ and t = Unix.time () in
+ let result =
+ let c = pgc ()
+ in
+  [ (List.hd alist) @ [asvar] ]
+  @
+  Sort.list
+   (fun l m -> List.hd l < List.hd m)
+   (List.fold_left
+    (fun parziale xres ->
+     (*let r1 = helm_property_id usek
+     and r2 = helm_property_id "position"
+     and r3 = helm_property_id "occurrence"
      in
-     (*let _ = print_endline ("use: " ^ qq) in*)
-     let res = c#exec qq in
-      parziale
-      @
-      if not (List.mem asvar (List.tl (List.hd alist))) then
-       List.map
+      let qq = "select distinct t" ^ r3 ^ ".att1, t" ^ r2 ^ ".att1 " ^
+       "from t" ^ r3 ^ ", t" ^ r2 ^ ", t" ^ r1 ^ " " ^
+       "where " ^ "t" ^ r1 ^ ".att0 = '" ^ (List.hd xres) ^ "' and t" ^ r1 ^
+       ".att1 = t" ^ r2 ^ ".att0 and t" ^ r1 ^ ".att1 = t" ^ r3 ^
+       ".att0 order by t" ^ r3 ^ ".att1 asc"*)
+      let tv = pgresult_to_string (c#exec ("select id from registry where uri='" ^ (List.hd xres) ^ "'")) in
+      let qq = "select uri, context from t" ^ tv ^ " where back_for='" ^ usek ^ "'"
+      in
+      let res = c#exec qq in
+       (List.map
         (fun l -> [List.hd l] @ List.tl xres @ List.tl l)
         res#get_list
-      else
-       List.map
-        (fun l ->
-         let t =
-          match xres with
-             hd::tl -> (List.hd l)::tl
-          |  [] -> []
-         in
-         List.map
-           snd
-          (Utility.set_assoc
-           asvar
-           (List.hd (List.tl l))
-           (List.combine (List.hd alist) t)
-          )
-        )
-        (List.find_all
-         (fun l ->
-          let currv =
-           List.hd (List.tl l)
-          and xresv =
-           try (
-            List.assoc
-             asvar
-             (List.combine
-              (List.tl (List.hd alist))
-              (List.tl xres)
-             )
-           ) with
-            Not_found -> ""
-          in
-           xresv = "" or xresv = currv
-         )
-         res#get_list
-        )
+       )
+       @
+       parziale
+    )
+    []
+    (List.tl alist)
    )
-   [ (List.hd alist)
-     @
-     if not (List.mem asvar (List.tl (List.hd alist))) then
-      [asvar]
-     else
-      []
-   ]
-   (List.tl alist)
+ in
+  let _ = print_endline (string_of_float (Unix.time () -. t)); flush stdout in
+   result
 ;;