@query-doctor/core 0.4.2-rc.1 → 0.5.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1781,6 +1781,9 @@ var Statistics = class Statistics {
1781
1781
  });
1782
1782
  }
1783
1783
  }
1784
+ const sample = columnStatsValues.find((v) => v.table_name === "users" && v.stakind3 !== 0);
1785
+ if (sample) console.log("[stats debug] sample stakind3:", sample.stakind3, "stanumbers3:", sample.stanumbers3);
1786
+ else console.log("[stats debug] no users column found with non-zero stakind3");
1784
1787
  /**
1785
1788
  * Postgres has 5 different slots for storing statistics per column and a potentially unlimited
1786
1789
  * number of statistic types to choose from. Each code in `stakindN` can mean different things.
@@ -1989,7 +1992,9 @@ var Statistics = class Statistics {
1989
1992
  returning starelid, staattnum, stainherit, stakind1, stakind2, stakind3, stakind4, stakind5
1990
1993
  )
1991
1994
  select * from updated union all (select * from inserted); -- @qd_introspection`;
1992
- columnStatsUpdatePromise = tx.exec(sql, [columnStatsValues]).catch((err) => {
1995
+ columnStatsUpdatePromise = tx.exec(sql, [columnStatsValues]).then((rows) => {
1996
+ console.log("[stats debug] restore result rows:", JSON.stringify(rows));
1997
+ }).catch((err) => {
1993
1998
  console.error("Something wrong wrong updating column stats");
1994
1999
  console.error(err);
1995
2000
  throw err;
@@ -2084,24 +2089,27 @@ var Statistics = class Statistics {
2084
2089
  'columnName', c.column_name,
2085
2090
  'stats', (
2086
2091
  SELECT json_build_object(
2087
- 'starelid', s.starelid,
2088
- 'staattnum', s.staattnum,
2089
- 'stanullfrac', s.stanullfrac,
2090
- 'stawidth', s.stawidth,
2091
- 'stadistinct', s.stadistinct,
2092
- 'stakind1', s.stakind1, 'staop1', s.staop1, 'stacoll1', s.stacoll1, 'stanumbers1', s.stanumbers1,
2093
- 'stakind2', s.stakind2, 'staop2', s.staop2, 'stacoll2', s.stacoll2, 'stanumbers2', s.stanumbers2,
2094
- 'stakind3', s.stakind3, 'staop3', s.staop3, 'stacoll3', s.stacoll3, 'stanumbers3', s.stanumbers3,
2095
- 'stakind4', s.stakind4, 'staop4', s.staop4, 'stacoll4', s.stacoll4, 'stanumbers4', s.stanumbers4,
2096
- 'stakind5', s.stakind5, 'staop5', s.staop5, 'stacoll5', s.stacoll5, 'stanumbers5', s.stanumbers5,
2097
- 'stavalues1', CASE WHEN $1 THEN s.stavalues1 ELSE NULL END,
2098
- 'stavalues2', CASE WHEN $1 THEN s.stavalues2 ELSE NULL END,
2099
- 'stavalues3', CASE WHEN $1 THEN s.stavalues3 ELSE NULL END,
2100
- 'stavalues4', CASE WHEN $1 THEN s.stavalues4 ELSE NULL END,
2101
- 'stavalues5', CASE WHEN $1 THEN s.stavalues5 ELSE NULL END
2092
+ 'starelid', cl.oid,
2093
+ 'staattnum', a.attnum,
2094
+ 'stanullfrac', ps.null_frac,
2095
+ 'stawidth', ps.avg_width,
2096
+ 'stadistinct', ps.n_distinct,
2097
+ 'stakind1', CASE WHEN ps.most_common_vals IS NOT NULL THEN 1 ELSE 0 END, 'staop1', 0, 'stacoll1', 0, 'stanumbers1', ps.most_common_freqs,
2098
+ 'stakind2', CASE WHEN ps.histogram_bounds IS NOT NULL THEN 2 ELSE 0 END, 'staop2', 0, 'stacoll2', 0, 'stanumbers2', NULL,
2099
+ 'stakind3', CASE WHEN ps.correlation IS NOT NULL THEN 3 ELSE 0 END, 'staop3', 0, 'stacoll3', 0, 'stanumbers3', CASE WHEN ps.correlation IS NOT NULL THEN ARRAY[ps.correlation]::float4[] ELSE NULL END,
2100
+ 'stakind4', CASE WHEN ps.most_common_elems IS NOT NULL THEN 4 ELSE 0 END, 'staop4', 0, 'stacoll4', 0,
2101
+ 'stanumbers4', ps.most_common_elem_freqs,
2102
+ 'stakind5', 0, 'staop5', 0, 'stacoll5', 0, 'stanumbers5', NULL,
2103
+ 'stavalues1', CASE WHEN $1 THEN ps.most_common_vals ELSE NULL END,
2104
+ 'stavalues2', CASE WHEN $1 THEN ps.histogram_bounds ELSE NULL END,
2105
+ 'stavalues3', NULL,
2106
+ 'stavalues4', CASE WHEN $1 THEN ps.most_common_elems ELSE NULL END,
2107
+ 'stavalues5', NULL
2102
2108
  )
2103
- FROM pg_statistic s
2104
- WHERE s.starelid = a.attrelid AND s.staattnum = a.attnum
2109
+ FROM pg_stats ps
2110
+ WHERE ps.schemaname = c.table_schema
2111
+ AND ps.tablename = c.table_name
2112
+ AND ps.attname = c.column_name
2105
2113
  )
2106
2114
  )
2107
2115
  ORDER BY c.ordinal_position