LCOV - code coverage report
Current view: top level - export/scratch1/home/monet/testing/b50e8e2d6f02-1-1-1/build/sql/backends/monet5 - 75_storagemodel.sql.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 2 100.0 %
Date: 2021-10-13 02:24:04 Functions: 1 1 100.0 %

          Line data    Source code
       1             : unsigned char _75_storagemodel_sql[7486] = {
       2             : "create function sys.\"storage\"()\n"
       3             : "returns table (\n"
       4             : "  \"schema\" varchar(1024),\n"
       5             : "  \"table\" varchar(1024),\n"
       6             : "  \"column\" varchar(1024),\n"
       7             : "  \"type\" varchar(1024),\n"
       8             : "  \"mode\" varchar(15),\n"
       9             : "  location varchar(1024),\n"
      10             : "  \"count\" bigint,\n"
      11             : "  typewidth int,\n"
      12             : "  columnsize bigint,\n"
      13             : "  heapsize bigint,\n"
      14             : "  hashes bigint,\n"
      15             : "  phash boolean,\n"
      16             : "  \"imprints\" bigint,\n"
      17             : "  sorted boolean,\n"
      18             : "  revsorted boolean,\n"
      19             : "  \"unique\" boolean,\n"
      20             : "  orderidx bigint\n"
      21             : ")\n"
      22             : "external name sql.\"storage\";\n"
      23             : "create view sys.\"storage\" as\n"
      24             : "select * from sys.\"storage\"()\n"
      25             : " where (\"schema\", \"table\") in (\n"
      26             : "  SELECT sch.\"name\", tbl.\"name\"\n"
      27             : "    FROM sys.\"tables\" AS tbl JOIN sys.\"schemas\" AS sch ON tbl.schema_id = sch.id\n"
      28             : "   WHERE tbl.\"system\" = FALSE)\n"
      29             : "order by \"schema\", \"table\", \"column\";\n"
      30             : "create view sys.\"tablestorage\" as\n"
      31             : "select \"schema\", \"table\",\n"
      32             : "  max(\"count\") as \"rowcount\",\n"
      33             : "  count(*) as \"storages\",\n"
      34             : "  sum(columnsize) as columnsize,\n"
      35             : "  sum(heapsize) as heapsize,\n"
      36             : "  sum(hashes) as hashsize,\n"
      37             : "  sum(\"imprints\") as imprintsize,\n"
      38             : "  sum(orderidx) as orderidxsize\n"
      39             : " from sys.\"storage\"\n"
      40             : "group by \"schema\", \"table\"\n"
      41             : "order by \"schema\", \"table\";\n"
      42             : "create view sys.\"schemastorage\" as\n"
      43             : "select \"schema\",\n"
      44             : "  count(*) as \"storages\",\n"
      45             : "  sum(columnsize) as columnsize,\n"
      46             : "  sum(heapsize) as heapsize,\n"
      47             : "  sum(hashes) as hashsize,\n"
      48             : "  sum(\"imprints\") as imprintsize,\n"
      49             : "  sum(orderidx) as orderidxsize\n"
      50             : " from sys.\"storage\"\n"
      51             : "group by \"schema\"\n"
      52             : "order by \"schema\";\n"
      53             : "create function sys.\"storage\"(sname varchar(1024))\n"
      54             : "returns table (\n"
      55             : "  \"schema\" varchar(1024),\n"
      56             : "  \"table\" varchar(1024),\n"
      57             : "  \"column\" varchar(1024),\n"
      58             : "  \"type\" varchar(1024),\n"
      59             : "  \"mode\" varchar(15),\n"
      60             : "  location varchar(1024),\n"
      61             : "  \"count\" bigint,\n"
      62             : "  typewidth int,\n"
      63             : "  columnsize bigint,\n"
      64             : "  heapsize bigint,\n"
      65             : "  hashes bigint,\n"
      66             : "  phash boolean,\n"
      67             : "  \"imprints\" bigint,\n"
      68             : "  sorted boolean,\n"
      69             : "  revsorted boolean,\n"
      70             : "  \"unique\" boolean,\n"
      71             : "  orderidx bigint\n"
      72             : ")\n"
      73             : "external name sql.\"storage\";\n"
      74             : "create function sys.\"storage\"(sname varchar(1024), tname varchar(1024))\n"
      75             : "returns table (\n"
      76             : "  \"schema\" varchar(1024),\n"
      77             : "  \"table\" varchar(1024),\n"
      78             : "  \"column\" varchar(1024),\n"
      79             : "  \"type\" varchar(1024),\n"
      80             : "  \"mode\" varchar(15),\n"
      81             : "  location varchar(1024),\n"
      82             : "  \"count\" bigint,\n"
      83             : "  typewidth int,\n"
      84             : "  columnsize bigint,\n"
      85             : "  heapsize bigint,\n"
      86             : "  hashes bigint,\n"
      87             : "  phash boolean,\n"
      88             : "  \"imprints\" bigint,\n"
      89             : "  sorted boolean,\n"
      90             : "  revsorted boolean,\n"
      91             : "  \"unique\" boolean,\n"
      92             : "  orderidx bigint\n"
      93             : ")\n"
      94             : "external name sql.\"storage\";\n"
      95             : "create function sys.\"storage\"(sname varchar(1024), tname varchar(1024), cname varchar(1024))\n"
      96             : "returns table (\n"
      97             : "  \"schema\" varchar(1024),\n"
      98             : "  \"table\" varchar(1024),\n"
      99             : "  \"column\" varchar(1024),\n"
     100             : "  \"type\" varchar(1024),\n"
     101             : "  \"mode\" varchar(15),\n"
     102             : "  location varchar(1024),\n"
     103             : "  \"count\" bigint,\n"
     104             : "  typewidth int,\n"
     105             : "  columnsize bigint,\n"
     106             : "  heapsize bigint,\n"
     107             : "  hashes bigint,\n"
     108             : "  phash boolean,\n"
     109             : "  \"imprints\" bigint,\n"
     110             : "  sorted boolean,\n"
     111             : "  revsorted boolean,\n"
     112             : "  \"unique\" boolean,\n"
     113             : "  orderidx bigint\n"
     114             : ")\n"
     115             : "external name sql.\"storage\";\n"
     116             : "create table sys.storagemodelinput(\n"
     117             : "  \"schema\" varchar(1024) NOT NULL,\n"
     118             : "  \"table\" varchar(1024) NOT NULL,\n"
     119             : "  \"column\" varchar(1024) NOT NULL,\n"
     120             : "  \"type\" varchar(1024) NOT NULL,\n"
     121             : "  typewidth int NOT NULL,\n"
     122             : "  \"count\" bigint NOT NULL,\n"
     123             : "  \"distinct\" bigint NOT NULL,\n"
     124             : "  atomwidth int NOT NULL,\n"
     125             : "  reference boolean NOT NULL DEFAULT FALSE,\n"
     126             : "  sorted boolean,\n"
     127             : "  \"unique\" boolean,\n"
     128             : "  isacolumn boolean NOT NULL DEFAULT TRUE\n"
     129             : ");\n"
     130             : "create procedure sys.storagemodelinit()\n"
     131             : "begin\n"
     132             : "  delete from sys.storagemodelinput;\n"
     133             : "  insert into sys.storagemodelinput\n"
     134             : "  select \"schema\", \"table\", \"column\", \"type\", typewidth, \"count\",\n"
     135             : "          case when (\"unique\" or \"type\" IN ('varchar', 'char', 'clob', 'json', 'url', 'blob', 'geometry', 'geometrya'))\n"
     136             : "                  then \"count\" else 0 end,\n"
     137             : "          case when \"count\" > 0 and heapsize >= 8192 and \"type\" in ('varchar', 'char', 'clob', 'json', 'url')\n"
     138             : "                  then cast((heapsize - 8192) / \"count\" as bigint)\n"
     139             : "          when \"count\" > 0 and heapsize >= 32 and \"type\" in ('blob', 'geometry', 'geometrya')\n"
     140             : "                  then cast((heapsize - 32) / \"count\" as bigint)\n"
     141             : "          else typewidth end,\n"
     142             : "          FALSE, case sorted when true then true else false end, \"unique\", TRUE\n"
     143             : "    from sys.\"storage\";\n"
     144             : "  update sys.storagemodelinput\n"
     145             : "     set reference = TRUE\n"
     146             : "   where (\"schema\", \"table\", \"column\") in (\n"
     147             : "          SELECT fkschema.\"name\", fktable.\"name\", fkkeycol.\"name\"\n"
     148             : "            FROM  sys.\"keys\" AS fkkey,\n"
     149             : "                  sys.\"objects\" AS fkkeycol,\n"
     150             : "                  sys.\"tables\" AS fktable,\n"
     151             : "                  sys.\"schemas\" AS fkschema\n"
     152             : "          WHERE fktable.\"id\" = fkkey.\"table_id\"\n"
     153             : "            AND fkkey.\"id\" = fkkeycol.\"id\"\n"
     154             : "            AND fkschema.\"id\" = fktable.\"schema_id\"\n"
     155             : "            AND fkkey.\"rkey\" > -1 );\n"
     156             : "  update sys.storagemodelinput\n"
     157             : "     set isacolumn = FALSE\n"
     158             : "   where (\"schema\", \"table\", \"column\") NOT in (\n"
     159             : "          SELECT sch.\"name\", tbl.\"name\", col.\"name\"\n"
     160             : "            FROM sys.\"schemas\" AS sch,\n"
     161             : "                  sys.\"tables\" AS tbl,\n"
     162             : "                  sys.\"columns\" AS col\n"
     163             : "          WHERE sch.\"id\" = tbl.\"schema_id\"\n"
     164             : "            AND tbl.\"id\" = col.\"table_id\");\n"
     165             : "end;\n"
     166             : "create function sys.columnsize(tpe varchar(1024), count bigint)\n"
     167             : "returns bigint\n"
     168             : "begin\n"
     169             : "  if tpe in ('tinyint', 'boolean')\n"
     170             : "          then return count;\n"
     171             : "  end if;\n"
     172             : "  if tpe = 'smallint'\n"
     173             : "          then return 2 * count;\n"
     174             : "  end if;\n"
     175             : "  if tpe in ('int', 'real', 'date', 'time', 'timetz', 'sec_interval', 'day_interval', 'month_interval')\n"
     176             : "          then return 4 * count;\n"
     177             : "  end if;\n"
     178             : "  if tpe in ('bigint', 'double', 'timestamp', 'timestamptz', 'inet', 'oid')\n"
     179             : "          then return 8 * count;\n"
     180             : "  end if;\n"
     181             : "  if tpe in ('hugeint', 'decimal', 'uuid', 'mbr')\n"
     182             : "          then return 16 * count;\n"
     183             : "  end if;\n"
     184             : "  if tpe in ('varchar', 'char', 'clob', 'json', 'url')\n"
     185             : "          then return 4 * count;\n"
     186             : "  end if;\n"
     187             : "  if tpe in ('blob', 'geometry', 'geometrya')\n"
     188             : "          then return 8 * count;\n"
     189             : "  end if;\n"
     190             : "  return 8 * count;\n"
     191             : "end;\n"
     192             : "create function sys.heapsize(tpe varchar(1024), count bigint, distincts bigint, avgwidth int)\n"
     193             : "returns bigint\n"
     194             : "begin\n"
     195             : "  if tpe in ('varchar', 'char', 'clob', 'json', 'url')\n"
     196             : "          then return 8192 + ((avgwidth + 8) * distincts);\n"
     197             : "  end if;\n"
     198             : "  if tpe in ('blob', 'geometry', 'geometrya')\n"
     199             : "          then return 32 + (avgwidth * count);\n"
     200             : "  end if;\n"
     201             : "  return 0;\n"
     202             : "end;\n"
     203             : "create function sys.hashsize(b boolean, count bigint)\n"
     204             : "returns bigint\n"
     205             : "begin\n"
     206             : "  if b = true\n"
     207             : "          then return 8 * count;\n"
     208             : "  end if;\n"
     209             : "  return 0;\n"
     210             : "end;\n"
     211             : "create function sys.imprintsize(tpe varchar(1024), count bigint)\n"
     212             : "returns bigint\n"
     213             : "begin\n"
     214             : "  if tpe in ('tinyint', 'boolean')\n"
     215             : "          then return cast(0.2 * count as bigint);\n"
     216             : "  end if;\n"
     217             : "  if tpe = 'smallint'\n"
     218             : "          then return cast(0.4 * count as bigint);\n"
     219             : "  end if;\n"
     220             : "  if tpe in ('int', 'real', 'date', 'time', 'timetz', 'sec_interval', 'day_interval', 'month_interval')\n"
     221             : "          then return cast(0.8 * count as bigint);\n"
     222             : "  end if;\n"
     223             : "  if tpe in ('bigint', 'double', 'timestamp', 'timestamptz', 'inet', 'oid')\n"
     224             : "          then return cast(1.6 * count as bigint);\n"
     225             : "  end if;\n"
     226             : "  if tpe in ('hugeint', 'decimal', 'uuid', 'mbr')\n"
     227             : "          then return cast(3.2 * count as bigint);\n"
     228             : "  end if;\n"
     229             : "  return 0;\n"
     230             : "end;\n"
     231             : "create view sys.storagemodel as\n"
     232             : "select \"schema\", \"table\", \"column\", \"type\", \"count\",\n"
     233             : "  sys.columnsize(\"type\", \"count\") as columnsize,\n"
     234             : "  sys.heapsize(\"type\", \"count\", \"distinct\", \"atomwidth\") as heapsize,\n"
     235             : "  sys.hashsize(\"reference\", \"count\") as hashsize,\n"
     236             : "  case when isacolumn then sys.imprintsize(\"type\", \"count\") else 0 end as imprintsize,\n"
     237             : "  case when (isacolumn and not sorted) then cast(8 * \"count\" as bigint) else 0 end as orderidxsize,\n"
     238             : "  sorted, \"unique\", isacolumn\n"
     239             : " from sys.storagemodelinput\n"
     240             : "order by \"schema\", \"table\", \"column\";\n"
     241             : "create view sys.tablestoragemodel as\n"
     242             : "select \"schema\", \"table\",\n"
     243             : "  max(\"count\") as \"rowcount\",\n"
     244             : "  count(*) as \"storages\",\n"
     245             : "  sum(sys.columnsize(\"type\", \"count\")) as columnsize,\n"
     246             : "  sum(sys.heapsize(\"type\", \"count\", \"distinct\", \"atomwidth\")) as heapsize,\n"
     247             : "  sum(sys.hashsize(\"reference\", \"count\")) as hashsize,\n"
     248             : "  sum(case when isacolumn then sys.imprintsize(\"type\", \"count\") else 0 end) as imprintsize,\n"
     249             : "  sum(case when (isacolumn and not sorted) then cast(8 * \"count\" as bigint) else 0 end) as orderidxsize\n"
     250             : " from sys.storagemodelinput\n"
     251             : "group by \"schema\", \"table\"\n"
     252             : "order by \"schema\", \"table\";\n"
     253             : };
     254             : #include "monetdb_config.h"
     255             : #include "sql_import.h"
     256             : #ifdef _MSC_VER
     257             : #undef read
     258             : #pragma section(".CRT$XCU",read)
     259             : #endif
     260         256 : LIB_STARTUP_FUNC(init_75_storagemodel_sql)
     261         256 : { sql_register("75_storagemodel", _75_storagemodel_sql); }

Generated by: LCOV version 1.14