java recordset 过滤器_性能 – Delphi ADO数据集过滤器

在我正在构建的应用程序中,我有一个大型数据库,其中一个表“人员”表示100,000行.此外,该表中的条目包含两种类型的数据:

父类型和子类型,其中每个子类型条目在特殊的“Child_OF”列中具有其父类型的数据库ID.

在内存中,两个db条目类型都由相应的类“TParent”和“TChild”表示,其中每个父类具有字段“children:TList”.

使用ADO的最快方法是:

– 创建一个父母列表,并正确地为他们分配他们的孩子……

我看待它的方式……人们可以解决这个问题

1)从表中检索所有父项(通过一个sql查询)并创建具有空子列表的父列表.

2)批量检索所有孩子,并为每个父母尝试从相应的数据集中找到他/她的孩子.

以下是我为该计划的分配阶段所考虑的一个例子……

procedure assignParentsTheirChildren(parentList: TList;

ma_people: TADOTable);

var

i: Integer;

qry: TADOQuery;

aChild: TChild;

aParent: TParent;

begin

// create the query

qry := TADOQuery.Create(nil);

qry.Connection := ma_people.Connection;

// set the sql statement to fetch all children ...

qry.SQL.Clear;

qry.SQL.Add('Select * from ' + ma_people.TableName + ' WHERE ChildOF <> ' +

QuotedStr(''));

// supposedly do some optimization---

qry.CursorLocation := clUseClient; // load whole recordset in memory

qry.DisableControls;

// disable controls ensures that no dataset bound control will be updated while iterating the recordset

qry.CursorType := ctStatic; // set cursor to static

// open dataset

qry.Open;

// ***EDIT*** for completeness I add the suggestion made by Agustin Seifert below

qry.RecordSet.Fields['ChildOf'].Properties.Item['Optimize'].value := true;

for i := 0 to parentList.count - 1 do

begin

// get daddy

aParent := parentList[i];

qry.Filter := 'ChildOF = ' + QuotedStr(IntToStr(aParent.parentID));

qry.Filtered := true;

while (not qry.EOF) do

begin

aChild := TChild.Create;

getChildFromQuery(aChild, qry); // fills in the fields of TChild class...

aParent.children.Add(aChild);

qry.Next;

end;

end;

qry.Free;

end;

我想上面代码的最大瓶颈是我正在为每个新父级过滤数据.使用seek()或locate / find …是否有更快的返工?基本上可以假设我的数据集是静态的(在创建父项列表期间)和网络延迟无限:)(也就是说,我首先想要从内存中执行子项到父项的分配).

非常感谢!

顺便说一下我使用的是Microsoft SQL Server 2012.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值