Skip to content

Devops: Run-state check that lists every write to a compiled query during a run - #3105

Merged
mathiasrw merged 1 commit into
mainfrom
fix/2596-find-writes
Nov 22, 2026
Merged

mathiasrw merged 1 commit into
mainfrom
fix/2596-find-writes

Conversation

@mathiasrw

@mathiasrw mathiasrw commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Part of #2596, and only its first step, find every write. It does not close the issue.

What is in the PR

A test tool, test/runstate/, and nothing under src/. It runs the suite and lists every place that writes to a compiled query object, or to one of its sources, while a statement runs. That list is the work list for step 2 of the issue, where each run gets its own object.

  • test/runstate/record.js is a preload for bun test. It wraps Select.prototype.compile and changes the query object and its sources in place when a compile returns, so that a write is recorded and then done as before.
  • test/runstate/run.js runs the suite with it and turns each place in dist/alasql.fs.js into a file and a line in src/.
  • yarn test-runstate builds and prints the list. test/runstate/README.md says how to read it and what it does not see.

The issue suggests Object.freeze in a test build. A frozen object throws at the first write, so a run shows one write and then stops, and the engine has to be changed to try it. The recorder lets every run finish and needs no test build. The suite gives the same answer with it, 2723 pass, 213 skip, 0 fail.

No new dependency. package.json gets one script line, .gitignore one folder. The check is not in CI, because the list is not empty yet. After step 2 it is expected to be empty and can become a job then.

The list

From bun test/runstate/run.js --compile on this branch. The columns are the property, the place that writes it, the first test file that made the write, and the line as it is in the bundle. [] after a name is a write inside an array the compile made. When several source lines have the same text, the nearest is given and the others are in brackets.

suite: 2723 pass, 213 skip, 0 fail (exit code 0)

writes to the query object during a run: 24 properties, 60 places
  A                src/select/queryfn.js:35           test000.js  | query.A = A;
  B                src/select/queryfn.js:36           test000.js  | query.B = B;
  cb               src/select/queryfn.js:37           test000.js  | query.cb = cb;
  columns          src/select/pivot.js:204            test354.js  | query2.columns = query2.columns.filter(function(col) {
  columns          src/select/queryfn.js:500 (or 473) test005.js  | query.columns = query.columns.filter(function(column) {
  columns[]        generated code, called from src/select/select.js:783 test1264.js
  data             src/engine/core.js:318             test000.js  | statement.query.data = [];
  data             src/select/pivot.js:178 (or 365)   test354.js  | query2.data = data;
  data             src/select/pivot.js:365 (or 178)   test355.js  | query.data = data;
  data             src/select/queryfn.js:121 (or 167, 570) test000.js  | query.data = [];
  data             src/select/queryfn.js:167 (or 121, 570) test001.js  | query.data = [];
  data             src/select/queryfn.js:281 (or 429) test1965.js  | query.data = query.data.sort(query.orderfn);
  data             src/select/queryfn.js:332          test017.js  | query.data = query.data.concat(ud);
  data             src/select/queryfn.js:361          test017.js  | query.data = arrayUnionDeep(query.data, ud);
  data             src/select/queryfn.js:377          test022.js  | query.data = arrayExceptDeep(query.data, ud);
  data             src/select/queryfn.js:394          test022.js  | query.data = arrayIntersectDeep(query.data, ud);
  data             src/select/queryfn.js:429 (or 281) test001.js  | query.data = query.data.sort(query.orderfn);
  data             src/select/queryfn.js:442          test1125.js  | query.data = query.data.filter(function(r2) {
  data             src/select/queryfn.js:549          test030.js  | query.data = query.data.slice(offset, limit);
  data             src/select/queryfn.js:570 (or 121, 167) test130-B.js  | query.data = [];
  explaination[]   generated code, called from src/select/queryfn.js:431 test148.js
  explid           src/select/queryfn.js:432          test148.js  | explid: query.explid++,
  groups           src/select/queryfn.js:123          test000.js  | query.groups = [];
  groups           src/select/queryfn.js:183          test1967.js  | query.groups = [g];
  joinat           src/select/queryfn.js:131          test2910.js  | query.joinat = [];
  joinat           src/select/queryfn.js:159          test2910.js  | query.joinrows = query.joinat = void 0;
  joinrows         src/select/queryfn.js:130          test2910.js  | query.joinrows = [];
  joinrows         src/select/queryfn.js:159          test2910.js  | query.joinrows = query.joinat = void 0;
  limit            src/select/select.js:454           test1381.js  | query.limit = params2 ? params2[query.limitParam] : void 0;
  modifier         src/select/exists.js:47 (or 54)    test1645.js  | nq.query.modifier = "RECORDSET";
  modifier         src/select/exists.js:54 (or 47)    test1904.js  | nq.query.modifier = "RECORDSET";
  modifier         src/select/queryfn.js:308          test1264.js  | query.unionallfn.query.modifier = void 0;
  modifier         src/select/queryfn.js:312          test017.js  | query.unionallfn.query.modifier = "RECORDSET";
  modifier         src/select/queryfn.js:336          test1264.js  | query.unionfn.query.modifier = "ARRAY";
  modifier         src/select/queryfn.js:340          test017.js  | query.unionfn.query.modifier = "RECORDSET";
  modifier         src/select/queryfn.js:365          test254.js  | query.exceptfn.query.modifier = "ARRAY";
  modifier         src/select/queryfn.js:369          test022.js  | query.exceptfn.query.modifier = "RECORDSET";
  modifier         src/select/queryfn.js:381          test254.js  | query.intersectfn.query.modifier = void 0;
  modifier         src/select/queryfn.js:385          test022.js  | query.intersectfn.query.modifier = "RECORDSET";
  modifier         src/statements/delete.js:60 (or 52) test231.js  | nq.query.modifier = "RECORDSET";
  modifier         src/statements/insert.js:131 (or 124) test1211.js  | nq.query.modifier = "RECORDSET";
  modifier         src/statements/set.js:32 (or 39)   test1904.js  | if (nq.query && !nq.query.modifier) nq.query.modifier = "RECORDSET";
  modifier         src/statements/set.js:39 (or 32)   test1904.js  | if (nq.query && !nq.query.modifier) nq.query.modifier = "RECORDSET";
  modifier         src/statements/update.js:67 (or 60) test684.js  | nq.query.modifier = "RECORDSET";
  offset           src/select/select.js:457           test1381.js  | query.offset = params2 ? params2[query.offsetParam] : void 0;
  oldscope         src/select/queryfn.js:38           test000.js  | query.oldscope = oldscope;
  params           src/select/queryfn.js:51           test024.js  | q.query.params = query.params;
  params           src/select/select.js:452           test000.js  | query.params = params2;
  queriesdata      src/select/queryfn.js:48           test017.js  | query.queriesdata = [];
  queriesfn        src/select/from.js:22              test054.js  | source.subquery.query.queriesfn = query.queriesfn;
  query            src/select/queryfn.js:34           test000.js  | query.query = query;
  removeKeys[]     generated code, called from src/select/queryfn.js:276 (or 420) test1965.js
  removeKeys[]     generated code, called from src/select/queryfn.js:420 (or 276) test017.js
  scope            src/select/queryfn.js:56           test000.js  | query.scope = oldscope ? cloneDeep(oldscope) : {};
  sourceslen       src/select/queryfn.js:32           test000.js  | query.sourceslen = query.sources.length;
  sourceslen       src/select/queryfn.js:45           test017.js  | query.sourceslen += query.queriesfn.length;
  sourceslen       src/select/queryfn.js:107          test000.js  | query.sourceslen--;
  subqueryCache    generated code                     test024.js
  subqueryCache    src/select/queryfn.js:41           test000.js  | query.subqueryCache = {};
  xgroups          src/select/queryfn.js:122          test000.js  | query.xgroups = {};

writes to the source object during a run: 8 properties, 15 places
  columns          src/formats/from.js:400 (or 382)   test1171.js  | var columns = query.sources[idx].columns = [];
  columns          src/storage/sqljs.js:132           test1284.js  | var columns = query.sources[idx].columns = [];
  data             src/select/queryfn.js:94           test000.js  | source.data = data;
  data             src/select/queryfn.js:101          test141.js  | source.data = {};
  data             src/select/queryfn.js:717 (or 703) test118-B.js  | source.data = source.data.filter(function(r) {
  data             src/select/queryfn.js:737          test118-B.js  | source.data = res;
  dontcache        src/select/queryfn.js:97           test141.js  | source.dontcache = source.getfn.dontcache;
  dontcache        src/select/queryfn.js:99           test141.js  | source.dontcache = false;
  getfn            src/select/queryfn.js:96           test141.js  | source.getfn = source.data;
  ix               src/select/queryfn.js:609 (or 662) test001.js  | source.ix = ixx;
  ix               src/select/queryfn.js:614 (or 667) test001.js  | source.ix = {};
  queriesdata      src/select/queryfn.js:77           test000.js  | source.queriesdata = query.queriesdata;
  query            src/select/queryfn.js:62           test000.js  | source.query = query;
  rowat            src/select/queryfn.js:134          test2910.js  | source.rowat = /* @__PURE__ */ new Map();
  rowat            src/select/queryfn.js:161          test2910.js  | source.rowat = void 0;

writes to a finished query during a later compile: 6 places
  query.isCorrelated     src/select/select.js:672           test024.js
  query.modifier         src/select/from.js:123             test018.js
  query.modifier         src/select/join.js:115             test1263.js
  query.modifier         src/select/select.js:610 (or 669)  test019.js
  query.modifier         src/select/select.js:669 (or 610)  test024.js
  query.queriesfn        src/select/select.js:694           test024.js

In short, a run writes 24 properties of the query object from 60 places and 8 properties of a source from 15 places.

  • Almost all of it is in src/select/queryfn.js, the per-run notepad the issue describes (params, data, groups, xgroups, scope, cb, sourceslen, source.data, source.ix).
  • modifier is written on the query of a subquery, of a UNION part, and of the SELECT inside INSERT, UPDATE, DELETE and SET, each time the outer statement runs. These are writes to another statement's compiled object, so step 2 has to cover them as well as the query's own fields.
  • queriesfn is copied from the outer query to the subquery of a source during a run (src/select/from.js line 22), which is Give each SELECT its own list of subqueries from parsing on #2666.
  • Four writes come from generated code. subqueryCache is written by the code for IN (subquery) (src/expression/expression.js lines 338 and 373), and removeKeys, columns and explaination get items pushed during a run, so they grow with every run of a cached statement.
  • statement.query.data = [] in cleanupCache (src/engine/core.js line 318) is the cleanup the issue says step 2 makes unneeded.

The last block is not run state. It is a parent compile that changes the query of a subquery that is already compiled. It is listed because step 2 will meet it.

Write sites the suite does not reach

The recorder only sees code that a test runs. A text search for assignments to query. and source. in the files above gives these places that no test reached. I did not write tests to reach them.

Place Line
src/select/queryfn.js 454 query.removeKeys.push('$$hashKey'), only when angular is defined
src/select/queryfn.js 662, 664, 667, 708, 739 source.ix and source.data in the index branches of preIndex
src/select/pivot.js 43 query.columns = [] when PIVOT has no rows
src/select/dojoin.js 179 to 183, 191, 192 two sources swap their join functions and their place in query.sources

Three more places write inside a value that a run assigned, so they are not shared state by themselves and are not in the list. They are query.queriesdata[-idx - 1] (queryfn.js 104), query.joinat[h] (dojoin.js 80) and query.columns.push(nc) (pivot.js 251). source.data[i] = dataw (queryfn.js 626, 681, 732) writes into the array a source handed out, which can be the data of a table.

What the check does not see

Parity differences

None. No file under src/ and nothing in the build changes, and the parity job of this PR gives 0 differences in 78,515 aligned statements (result 0, error 0, params 0, generated code 0, only in one recording 0, diverged 0), 0 changed API paths of 1,718, and the same sizes.

The next step, not started

Step 2 of the issue. Give each run Object.create(query) and the same for each source, including the queries of subqueries and UNION parts that the list shows, then remove the guard of #2465 and #2747 and cleanupCache, add the tests the issue names, and run this check until the list is empty.

@mathiasrw
mathiasrw merged commit 41040e4 into main Nov 22, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant