瀏覽代碼

- for /updates with count <=15 use 'case .. when .. then' pattern, for count > 15 - 'unnest' pattern (#8031)

- using binary parameter binding format for Int4/Int8 parameter types - should be faster than textual

Co-authored-by: pavel.mash <[email protected]>
pavelmash 2 年之前
父節點
當前提交
e5c8016718
共有 2 個文件被更改,包括 8 次插入6 次删除
  1. 1 1
      frameworks/Pascal/mormot/setup_and_build.sh
  2. 7 5
      frameworks/Pascal/mormot/src/raw.pas

+ 1 - 1
frameworks/Pascal/mormot/setup_and_build.sh

@@ -35,7 +35,7 @@ echo "Download statics from $URL ..."
 wget -qO- "$URL" | tar -xz -C ./libs/mORMot/static
 wget -qO- "$URL" | tar -xz -C ./libs/mORMot/static
 
 
 # uncomment for fixed commit URL
 # uncomment for fixed commit URL
-URL=https://github.com/synopse/mORMot2/tarball/46f5360a668ccf7a7c4d538fb319b449da8a232f
+URL=https://github.com/synopse/mORMot2/tarball/c57d48846f050f4f68856758d28cf76450addaf2
 #URL="https://api.github.com/repos/synopse/mORMot2/tarball/$USED_TAG"
 #URL="https://api.github.com/repos/synopse/mORMot2/tarball/$USED_TAG"
 echo "Download and unpacking mORMot sources from $URL ..."
 echo "Download and unpacking mORMot sources from $URL ..."
 wget -qO- "$URL" | tar -xz -C ./libs/mORMot  --strip-components=1
 wget -qO- "$URL" | tar -xz -C ./libs/mORMot  --strip-components=1

+ 7 - 5
frameworks/Pascal/mormot/src/raw.pas

@@ -295,7 +295,7 @@ function TRawAsyncServer.cached_queries(ctxt: THttpServerRequest): cardinal;
 var
 var
   i: PtrInt;
   i: PtrInt;
   res: TOrmWorlds;
   res: TOrmWorlds;
-  cache: POrmCacheEntry;
+  cache: POrmCacheTable;
 begin
 begin
   cache := fStore.Orm.Cache.Table(TOrmCachedWorld);
   cache := fStore.Orm.Cache.Table(TOrmCachedWorld);
   SetLength(res, GetQueriesParamValue(ctxt, 'COUNT='));
   SetLength(res, GetQueriesParamValue(ctxt, 'COUNT='));
@@ -479,14 +479,16 @@ begin
   cnt := getQueriesParamValue(ctxt);
   cnt := getQueriesParamValue(ctxt);
   if not getRawRandomWorlds(cnt, res) then
   if not getRawRandomWorlds(cnt, res) then
     exit;
     exit;
-  if cnt > 20 then
+  // generate new randoms
+  for i := 0 to cnt - 1 do
+    res[i].randomNumber := ComputeRandomWorld;
+  if cnt > 15 then
   begin
   begin
+    // fill parameters arrays for update with nested select (PostgreSQL only)
     setLength(ids{%H-}, cnt);
     setLength(ids{%H-}, cnt);
     setLength(nums{%H-}, cnt);
     setLength(nums{%H-}, cnt);
-    // generate new randoms, fill parameters arrays for update
     for i := 0 to cnt - 1 do
     for i := 0 to cnt - 1 do
     begin
     begin
-      res[i].randomNumber := ComputeRandomWorld;
       ids[i] := res[i].id;
       ids[i] := res[i].id;
       nums[i] := res[i].randomNumber;
       nums[i] := res[i].randomNumber;
     end;
     end;
@@ -496,10 +498,10 @@ begin
   end
   end
   else
   else
   begin
   begin
+    // fill parameters for update up to 15 items as CASE .. WHEN .. THEN ..
     stmt := conn.NewStatementPrepared(ComputeUpdateSql(cnt), false, true);
     stmt := conn.NewStatementPrepared(ComputeUpdateSql(cnt), false, true);
     for i := 0 to cnt - 1 do
     for i := 0 to cnt - 1 do
     begin
     begin
-      res[i].randomNumber := ComputeRandomWorld;
       stmt.Bind(i * 2 + 1, res[i].id);
       stmt.Bind(i * 2 + 1, res[i].id);
       stmt.Bind(i * 2 + 2, res[i].randomNumber);
       stmt.Bind(i * 2 + 2, res[i].randomNumber);
       stmt.Bind(cnt * 2 + i + 1, res[i].id);
       stmt.Bind(cnt * 2 + i + 1, res[i].id);