/ Check-in [4677ef2f]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add a new "testset" to the speedtest1 program: The sudoku solver.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4677ef2f8a726573c48ee2e532c00a68308dd7e1
User & Date: drh 2014-02-09 00:18:21
Context
2014-02-09
00:52
Add the Mandelbrot Set testcase to the "cte" testset of speedtest1. check-in: 56febbeb user: drh tags: trunk
00:18
Add a new "testset" to the speedtest1 program: The sudoku solver. check-in: 4677ef2f user: drh tags: trunk
2014-02-08
23:20
Do away with the "multi-register pseudo-table" abstration. Instead, just use an OP_SCopy to load results directory from the result registers of the co-routine. check-in: 1e64dd78 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/speedtest1.c.

   732    732     speedtest1_end_test();
   733    733   
   734    734   
   735    735     speedtest1_begin_test(990, "ANALYZE");
   736    736     speedtest1_exec("ANALYZE");
   737    737     speedtest1_end_test();
   738    738   }
          739  +
          740  +/*
          741  +** A testset for common table expressions.  This exercises code
          742  +** for views, subqueries, co-routines, etc.
          743  +*/
          744  +void testset_cte(void){
          745  +  static const char *azPuzzle[] = {
          746  +    /* Easy */
          747  +    "534...9.."
          748  +    "67.195..."
          749  +    ".98....6."
          750  +    "8...6...3"
          751  +    "4..8.3..1"
          752  +    "....2...6"
          753  +    ".6....28."
          754  +    "...419..5"
          755  +    "...28..79",
          756  +
          757  +    /* Medium */
          758  +    "53....9.."
          759  +    "6..195..."
          760  +    ".98....6."
          761  +    "8...6...3"
          762  +    "4..8.3..1"
          763  +    "....2...6"
          764  +    ".6....28."
          765  +    "...419..5"
          766  +    "....8..79",
          767  +
          768  +    /* Hard */
          769  +    "53......."
          770  +    "6..195..."
          771  +    ".98....6."
          772  +    "8...6...3"
          773  +    "4..8.3..1"
          774  +    "....2...6"
          775  +    ".6....28."
          776  +    "...419..5"
          777  +    "....8..79",
          778  +  };
          779  +  const char *zPuz;
          780  +
          781  +  if( g.szTest<25 ){
          782  +    zPuz = azPuzzle[0];
          783  +  }else if( g.szTest<70 ){
          784  +    zPuz = azPuzzle[1];
          785  +  }else{
          786  +    zPuz = azPuzzle[2];
          787  +  }
          788  +  speedtest1_begin_test(100, "Sudoku with recursive 'digits'");
          789  +  speedtest1_prepare(
          790  +    "WITH RECURSIVE\n"
          791  +    "  input(sud) AS (VALUES(?1)),\n"
          792  +    "  digits(z,lp) AS (\n"
          793  +    "    VALUES('1', 1)\n"
          794  +    "    UNION ALL\n"
          795  +    "    SELECT CAST(lp+1 AS TEXT), lp+1 FROM digits WHERE lp<9\n"
          796  +    "  ),\n"
          797  +    "  x(s, ind) AS (\n"
          798  +    "    SELECT sud, instr(sud, '.') FROM input\n"
          799  +    "    UNION ALL\n"
          800  +    "    SELECT\n"
          801  +    "      substr(s, 1, ind-1) || z || substr(s, ind+1),\n"
          802  +    "      instr( substr(s, 1, ind-1) || z || substr(s, ind+1), '.' )\n"
          803  +    "     FROM x, digits AS z\n"
          804  +    "    WHERE ind>0\n"
          805  +    "      AND NOT EXISTS (\n"
          806  +    "            SELECT 1\n"
          807  +    "              FROM digits AS lp\n"
          808  +    "             WHERE z.z = substr(s, ((ind-1)/9)*9 + lp, 1)\n"
          809  +    "                OR z.z = substr(s, ((ind-1)%%9) + (lp-1)*9 + 1, 1)\n"
          810  +    "                OR z.z = substr(s, (((ind-1)/3) %% 3) * 3\n"
          811  +    "                        + ((ind-1)/27) * 27 + lp\n"
          812  +    "                        + ((lp-1) / 3) * 6, 1)\n"
          813  +    "         )\n"
          814  +    "  )\n"
          815  +    "SELECT s FROM x WHERE ind=0;"
          816  +  );
          817  +  sqlite3_bind_text(g.pStmt, 1, zPuz, -1, SQLITE_STATIC);
          818  +  speedtest1_run();
          819  +  speedtest1_end_test();
          820  +
          821  +  speedtest1_begin_test(200, "Sudoku with VALUES 'digits'");
          822  +  speedtest1_prepare(
          823  +    "WITH RECURSIVE\n"
          824  +    "  input(sud) AS (VALUES(?1)),\n"
          825  +    "  digits(z,lp) AS (VALUES('1',1),('2',2),('3',3),('4',4),('5',5),\n"
          826  +    "                         ('6',6),('7',7),('8',8),('9',9)),\n"
          827  +    "  x(s, ind) AS (\n"
          828  +    "    SELECT sud, instr(sud, '.') FROM input\n"
          829  +    "    UNION ALL\n"
          830  +    "    SELECT\n"
          831  +    "      substr(s, 1, ind-1) || z || substr(s, ind+1),\n"
          832  +    "      instr( substr(s, 1, ind-1) || z || substr(s, ind+1), '.' )\n"
          833  +    "     FROM x, digits AS z\n"
          834  +    "    WHERE ind>0\n"
          835  +    "      AND NOT EXISTS (\n"
          836  +    "            SELECT 1\n"
          837  +    "              FROM digits AS lp\n"
          838  +    "             WHERE z.z = substr(s, ((ind-1)/9)*9 + lp, 1)\n"
          839  +    "                OR z.z = substr(s, ((ind-1)%%9) + (lp-1)*9 + 1, 1)\n"
          840  +    "                OR z.z = substr(s, (((ind-1)/3) %% 3) * 3\n"
          841  +    "                        + ((ind-1)/27) * 27 + lp\n"
          842  +    "                        + ((lp-1) / 3) * 6, 1)\n"
          843  +    "         )\n"
          844  +    "  )\n"
          845  +    "SELECT s FROM x WHERE ind=0;"
          846  +  );
          847  +  sqlite3_bind_text(g.pStmt, 1, zPuz, -1, SQLITE_STATIC);
          848  +  speedtest1_run();
          849  +  speedtest1_end_test();
          850  +}
   739    851   
   740    852   /*
   741    853   ** A testset used for debugging speedtest1 itself.
   742    854   */
   743    855   void testset_debug1(void){
   744    856     unsigned i, n;
   745    857     unsigned x1, x2;
................................................................................
   941   1053     }
   942   1054   
   943   1055     if( g.bExplain ) printf(".explain\n.echo on\n");
   944   1056     if( strcmp(zTSet,"main")==0 ){
   945   1057       testset_main();
   946   1058     }else if( strcmp(zTSet,"debug1")==0 ){
   947   1059       testset_debug1();
         1060  +  }else if( strcmp(zTSet,"cte")==0 ){
         1061  +    testset_cte();
   948   1062     }else{
   949   1063       fatal_error("unknown testset: \"%s\"\n", zTSet);
   950   1064     }
   951   1065     speedtest1_final();
   952   1066   
   953   1067     /* Database connection statistics printed after both prepared statements
   954   1068     ** have been finalized */