Notes on metaschema additions to replace hcg_struct data structures. RJLRef: $PH/COOL-BDE/metadataExtensions060822.2300 - RJL060822 Invarant metadata is now pre-computed by chgen -mweta. For bde, this metadata is saved by chgen to bde/schema/94sde_schema.msdat, but not yet utilized. The SV-->TT-->TA metaschema and its instantiation for a given .sch schemaafile (e.g. bde/schema/94sbde_schema.sch) can be augmented with static (but not invariant) properties of bde tables if this data is dynamically updated by the CRUD operations that are auto-generated by chgen/gencpp in bde/pr_util_*log). The 'horrible' access expression in get_rcount below shows that rcount (and maxkey) is currently located in what I call hcg_structs): In dprint.h: ------------------ /***********************************************************************/ /* Macro get_rcount returns the number of rows currently loaded in the */ /* specified table, iff in the specified view/version). [was pr_rcount]*/ /* If tbl is not a ttabbr in the view, 0 is returned. */ /* Side-effects: find_*_idx() updates [hcg_?]tbl_idx and hcg_view_id()x.*/ /***********************************************************************/ /* Added '&&find_tbl_idx(#tbl)' to condition. - RJL060806 */ /* find_tbl_idx updates hcg_tbl_idx, not tbl##_idx, or returns 0 -RJL060809 */ #define get_rcount(viewname,tbl) \ ((find_view_idx(viewname) && (find_tbl_idx(#tbl)) ) ? \ hcg_ts_list[hcg_tbl_idx].ts_list[hcg_view_list.view_list[hcg_view_idx].version_list[hcg_tbl_idx]].rcount : \ 0) ------------------- A new rcount data member in table TT can be initialized to 0 in metaschema file bdeischema.msdat by chgen or gencpp. Whenever pr_add_row allocates a new table-row it requires a new pkey. This is created by pr_gen_key and maxkey and rcount are incremented. (Since pkeys are never re-used, pr_delete() will decrement rcount but not maxkey.) Table TT has an index tbl_idx map(tbl) for each table abbrev XX. Since TTrows have fixed length and MAXROWS is known, they can be are pre-allocated in an array (TBD). Then a lookup table indexed by ttidx can map it to its address TTcurr: TTcurr = TTloc[tt_idx] = TTloc[0] + (tt_idx * (sizeof(struct TT)) Another map can produce bl_idzx from the table abbrev: ttidx = TTmap(ttabbrev); Then get_rcount(viewname,XX) would be simply expressed and efficiently computed without the find_*_idx searches as int get_rcount(char* viewname, char* tbl) { ttidx = TTmap(ttabbrev); TTcurr = TTbegin + (sizeof(struct TT))*(ttidx)); assert((tblInView(ttabbrev, viewname) ; return (TTcurr->rcount); } //tblInView checks the associative relation TV between TT and VV //to see if table ttabbrev is contained in view viewname. //It can be used to return an error if tbl is not in viewname. //It can use a pre-computed view_idx = VVmap(viewname). Background: Moving table statistics to tables TT and TV from the hcg_structsxa was always a (deferred) TBD. Two over-complex features made this change more complex than it needs to be now: (1) Version numbers were mantained in pkeys and manipulated according to constraints in views. (2) pr_init() guaranteed that pkeys are unique over a given list of .dat files. I want to remmove version numbers from pkeys and remove pr_init()'s scan of a list of files. pr_load can update maxkey and rcount for the single-file design DB that it loads: (1) Without version numbers in pkeys, CVS can handle version control. (2) Without pr_init(), each .dat file is an independent database; (there are no constraints on pkey overlap between two .dat files). (Namespaces add a top level of table type partitioning, There are no conflicts among table types in different namespaces.)