MDX Index Corruption With Empty Table

Posted by Jesús Pallarés Quintero on  2002-02-23 16:55:32

There is a problem with conditional MDX indexes when the index is created or reindexed and no records are qualified for the index. When the index has no records the root pointer may not be assigned. This will result in a corrupted index when the first qualified record is added.


status: CLOSED    Urgency: MEDIUM    As Of: 2002-02-23 16:55:32

Comment:

The method GSobjSortMDX.Destroy in unit gs6_mdx.pas must be patched to
prevent this. Add the following 8 lines of code where marked:

==============================

destructor GSobjSortMDX.Destroy;
var
   i: integer;
   pa: longint;
   ec: integer;
   elm: GSptrMDXElement;
begin
   Closing := true;
   for i := 0 to 30 do
      if NodeList[i] <> nil then
      begin
         pa := CurTag.Owner.GetAvailPage;
         if NodeList[i+1]  = nil then CurTag.RootBlock := pa;
         ec := NodeList[i]^.Entry_Ct;
         if i > 0 then dec(NodeList[i]^.Entry_Ct);
         NodeList[i]^.LastUsed := GSobjMDXTag(CurTag).MDXFinalAvail;
         CurTag.Owner.PageWrite(pa, NodeList[i]^, PagSize);
         if GSobjMDXTag(CurTag).MDXFirstAvail = 0 then
            GSobjMDXTag(CurTag).MdxFirstAvail := pa;
         GSobjMDXTag(CurTag).MDXFinalAvail := pa;
         elm := Addr(NodeList[i]^.Data_Ary[pred(ec) *  CurTag.EntryLength]);
         Move(elm^.Char_Fld, KeyWork[0], CurTag.KeyLength);
         KeyWork[CurTag.KeyLength] := #0;
         if NodeList[i+1] <> nil then
            AddToNode(i+1,pa,KeyWork);
         FreeMem(NodeList[i],PagSize);
      end;

{------ add this code}

   if CurTag.RootBlock = 0 then
   begin
      CurTag.RootBlock := CurTag.Owner.GetAvailPage;
      GetMem(NodeList[0],PagSize);
      FillChar(NodeList[0]^,PagSize,#0);
      CurTag.Owner.PageWrite(CurTag.RootBlock, NodeList[0]^, PagSize);
      FreeMem(NodeList[0],PagSize);
   end;

{------ end of added code}

   inherited Destroy;
end;

==================================================