* Use MergeSort instead of InsertSort on opening database

* Always fetch all records when there are some indexes

git-svn-id: trunk@9759 -
This commit is contained in:
joost 2008-01-14 21:12:07 +00:00
parent 923aac0390
commit 611e07202d

View File

@ -160,6 +160,7 @@ type
FBlobBuffers : array of PBlobBuffer; FBlobBuffers : array of PBlobBuffer;
FUpdateBlobBuffers: array of PBlobBuffer; FUpdateBlobBuffers: array of PBlobBuffer;
procedure FetchAll;
procedure BuildIndex(var AIndex : TBufIndex); procedure BuildIndex(var AIndex : TBufIndex);
function GetIndexDefs : TIndexDefs; function GetIndexDefs : TIndexDefs;
{$IFDEF ARRAYBUF} {$IFDEF ARRAYBUF}
@ -373,6 +374,12 @@ begin
inherited destroy; inherited destroy;
end; end;
procedure TBufDataset.FetchAll;
begin
repeat
until (getnextpacket < FPacketRecords) or (FPacketRecords = -1);
end;
procedure TBufDataset.BuildIndex(var AIndex: TBufIndex); procedure TBufDataset.BuildIndex(var AIndex: TBufIndex);
var PCurRecLinkItem : PBufRecLinkItem; var PCurRecLinkItem : PBufRecLinkItem;
p,l,q : PBufRecLinkItem; p,l,q : PBufRecLinkItem;
@ -401,6 +408,8 @@ var PCurRecLinkItem : PBufRecLinkItem;
begin begin
// This simply copies the index... // This simply copies the index...
if not assigned(AIndex.Fields) then
AIndex.Fields := FieldByName(AIndex.FieldsName);
{$IFNDEF ARRAYBUF} {$IFNDEF ARRAYBUF}
case AIndex.Fields.DataType of case AIndex.Fields.DataType of
ftString : Comparefunc := @DBCompareText; ftString : Comparefunc := @DBCompareText;
@ -695,8 +704,7 @@ end;
procedure TBufDataset.InternalLast; procedure TBufDataset.InternalLast;
begin begin
repeat FetchAll;
until (getnextpacket < FPacketRecords) or (FPacketRecords = -1);
with FCurrentIndex^ do with FCurrentIndex^ do
{$IFDEF ARRAYBUF} {$IFDEF ARRAYBUF}
if FLastRecInd <> 0 then FCurrentRecInd := FLastRecInd; if FLastRecInd <> 0 then FCurrentRecInd := FLastRecInd;
@ -1069,9 +1077,6 @@ begin
FRecordArray[FLastRecInd]:=IntAllocRecordBuffer; FRecordArray[FLastRecInd]:=IntAllocRecordBuffer;
end; end;
for IndexNr:= 1 to FIndexesCount-1 do
AddRecordToIndex(FIndexes[IndexNr],pb);
pb := pchar(FCurrentIndex^.FRecordArray[FCurrentIndex^.FLastRecInd]); pb := pchar(FCurrentIndex^.FRecordArray[FCurrentIndex^.FLastRecInd]);
{$ELSE} {$ELSE}
with FIndexes[0] do with FIndexes[0] do
@ -1079,9 +1084,6 @@ begin
FLastRecBuf^.next := pointer(IntAllocRecordBuffer); FLastRecBuf^.next := pointer(IntAllocRecordBuffer);
FLastRecBuf^.next^.prior := FLastRecBuf; FLastRecBuf^.next^.prior := FLastRecBuf;
for IndexNr:= 1 to FIndexesCount-1 do
AddRecordToIndex(FIndexes[IndexNr],FLastRecBuf);
FLastRecBuf := FLastRecBuf^.next; FLastRecBuf := FLastRecBuf^.next;
pb := pchar(pointer(FLastRecBuf)+sizeof(TBufRecLinkItem)*FMaxIndexesCount); pb := pchar(pointer(FLastRecBuf)+sizeof(TBufRecLinkItem)*FMaxIndexesCount);
@ -1139,6 +1141,8 @@ begin
begin begin
Result := grEOF; Result := grEOF;
FAllPacketsFetched := True; FAllPacketsFetched := True;
if FIndexesCount>0 then for x := 1 to FIndexesCount-1 do
BuildIndex(FIndexes[x]);
Exit; Exit;
end; end;
@ -1949,14 +1953,16 @@ begin
DatabaseError(SMaxIndexes); DatabaseError(SMaxIndexes);
{$ENDIF} {$ENDIF}
InternalAddIndex(AName,AFields);
// If not all packets are fetched, you can not sort properly. // If not all packets are fetched, you can not sort properly.
FPacketRecords:=-1; if not active then
FPacketRecords:=-1;
InternalAddIndex(AName,AFields);
end; end;
procedure TBufDataset.InternalAddIndex(const AName, AFields: string); procedure TBufDataset.InternalAddIndex(const AName, AFields: string);
var StoreIndNr : Integer; var StoreIndNr : Integer;
begin begin
if Active then FetchAll;
if FIndexesCount>0 then if FIndexesCount>0 then
StoreIndNr:=FCurrentIndex^.IndNr StoreIndNr:=FCurrentIndex^.IndNr
else else