chiark / gitweb /
New pared-down query for ipair_gettrades
authorIan Jackson <ian@liberator.(none)>
Sat, 26 Sep 2009 18:34:57 +0000 (19:34 +0100)
committerIan Jackson <ian@liberator.(none)>
Sat, 26 Sep 2009 18:34:57 +0000 (19:34 +0100)
yarrg/TODO
yarrg/rsvalue.c

index 817ac0e..ea6b3eb 100644 (file)
@@ -1,3 +1,7 @@
+create index sell_by_islandonly on sell (islandid, commodid, price);
+
+
+
 UPLOADER
 --------
 
index a4e70f6..fe9c992 100644 (file)
@@ -1,24 +1,30 @@
 /**/
 
+typedef struct {
+  int commodid, src_price, src_qty, dst_price, dst_qty;
+} Trade;
+
+typedef struct {
+  int ntrades;
+  Trade *trades;
+} IslandPair;
+
 #include "rscommon.h"
 
 static void ipair_gettrades(int si, int di) {
   char *stmt= masprintf
     ("SELECT\n"
+     " sell.commodid           commodid,\n"
      " sell.price              src_price,\n"
      " sum(sell.qty)           src_qty,\n"
      " buy.price               dst_price,\n"
-     " sum(buy.qty)            dst_qty,\n"
-     " commods.commodid                commodid,\n"
-     " commods.unitmass                unitmass,\n"
-     " commods.unitvolume      unitvolume\n"
-     " FROM commods\n"
-     " JOIN sell ON commods.commodid = sell.commodid\n"
-     " JOIN buy  ON commods.commodid = buy.commodid\n"
-     " WHERE buy.price > sell.price\n"
-     " AND sell.islandid=%d\n"
-     " AND buy.islandid=%d\n"
-     " GROUP BY commods.commodid, sell.price, buy.price\n",
+     " sum(buy.qty)            dst_qty\n"
+     " FROM sell JOIN buy\n"
+     "   ON sell.commodid = buy.commodid\n"
+     "  AND buy.price > sell.price\n"
+     " WHERE sell.islandid=%d\n"
+     "  AND buy.islandid=%d\n"
+     " GROUP BY sell.commodid, sell.price, buy.price\n",
      si, di);
   
   printf("SQL\n[\n%s\n]\n", stmt);