Continuing the discussion from Additional increased buffer sizes — STRING(1024) ⇒ STRING(2048):
(sorry for the new topic, apparently I can’t reply in the Beta area)
May I suggest that the code take an approach that uses dynamic buffer sizes
vs a preset limit that is well known to lead to problems.
Mark,
The next refreshed build makes every view and file position buffer in both template chains STRING(2048). For a Browse that is 1 KB more per loaded row, for a relation tree node it is 4x (512 to 2048). With a page-loaded browse that is one page of rows, so around 100 KB for a 50-row page, which nobody will notice. It only adds up in a file-loaded browse that keeps every row in the queue (100,000 rows = 200 MB of position storage, up from 100 MB) and in a large relation tree.
The RTL side is already dynamic: POSITION(view) returns a string that carries its own size, and a buffer longer than the position is harmless. The size comes from the SQL drivers: when a view has an ORDER set (the ABC templates always set one) the view position stores one flag byte per field of every file in the view, in front of the actual order data. The beta report that triggered the change was a four-file browse with a 590-column table in it, and that position measured 1,042 bytes. So the practical ceiling with 2048 is about 1,900 fields across the files of one ordered view. SQL Server allows up to 1,024 columns per table, so two very large tables joined in one ordered browse can still potentially exceed it. If you have a case where 2048 is too small, tell me the driver, the tables and their field counts in the View.
This is a SQL-only shape. TopSpeed and the other ISAM drivers never see it: their views run in the RTL’s own view engine, and that position is each file’s key value plus record pointer, with a small sort index when the engine sorts the rows itself. A four-file TPS browse position is a few dozen to a couple of hundred bytes, so the old 1024 was never close for ISAM and 2048 is just likely unused room there.
Our plan is to improve it in the RTL-drivers:
-
in the SQL drivers: pack the flags eight to a byte. That takes the 1,042-byte example down to about 270 bytes and makes 2048 cover around 15,000 fields per ordered view. That’s a driver-only change, rebuilt for the whole SQL family at once, and positions never leave the process, so nothing on disk is affected.
-
Make a “too-small buffer” error report itself. Today a truncated position fails quietly: RESET returns 0 and the following NEXT reports error 78. The Browse class and the Clarion-chain fill loop will compare the position length against the buffer once and then raise a clearly stated error naming the buffer. That one covers every driver, SQL or ISAM.
Why not a dynamic field in the browse queue itself: that field (ViewPosition) is a plain STRING that a lot of third-party browse code reads directly, so changing it to a reference or an ANY breaks that contract, and it would add per-row heap allocation and lifetime handling to every generated browse in both chains. Since the position is already sized by the RTL and the driver fix removes the bloat, the 2048 fixed storage field becomes pretty roomy, and we keep the generated code simpler.
Regarding the Beta area: you were not in the beta testers group yet. I just added you, so read-write in the Beta category is open to you now.
Bob,
Thanks for the detailed & thoughtful response, I really appreciate it.
While I haven’t hit the bug myself caused by the overflow of the saved POSTION, I can tell you that it was a problem that appeared over and over and over again in the (now retired) skype chats. So I just thought that the scrutiny that CW12 requires seemed like an opportunity to establish a new “contract”
Comparing generated source in 11.1 and 12.0.14000 to 12 wide will show Browse Position STRING(1024) changed to STRING(2048).
Rather that change to the constant 2048 make it an Equate e.g. Legacy code that had STRING(2048)
%[22]ValueConstruct STRING(_ViewPositionSize_) #<! Queue POSITION information
Define that in TPLEQU.CLW, or it could be an APP Setting the developer can decide and added to every root CLW in the Includes section.
_ViewPositionSize_ EQUATE(2048)
ABC has this code that complicates it by passing the size but I do not see it passed by any code in the shipping temlates.
#GROUP(%ConstructQueue, %pDescription='', %pAddMark = %True, %pPositionSize = 2048)
...
#IF(%pPositionSize > 0)
#INSERT(%MakeField, 'ViewPosition','', 'STRING('&%pPositionSize&')','Entry''s view position')
#ENDIF
Maybe add the equate like by changing the default to be 1=Equate:
#GROUP(%ConstructQueue, %pDescription='', %pAddMark = %True, %pPositionSize = 1)
...
#IF(%pPositionSize = 1) #! 1 is Default in Prototype
#INSERT(%MakeField, 'ViewPosition','', 'STRING(_ViewPositionSize_)','Entry''s view position')
#ELSIF(%pPositionSize > 1)
#INSERT(%MakeField, 'ViewPosition','', 'STRING('&%pPositionSize&')','Entry''s view position')
#ENDIF
An alternative make the 1024 or 2048 a global App setting %AppViewPositionSize.
Have an override setting in the Browse Template (and others). I would guess certain complex browses need the large position, not all of them.
Seems possible for an extension template to calculate an estimated view position size.