admin管理员组文章数量:1392002
I want to know the field definitions (field names, types, and sizes) for a group of PostgreSQL (it seems the database type does not really matter, it could be Oracle or SQL Server) tables using TFDTable
. The table has about 20 columns and 5 million records. But this line of code needs 20 seconds:
MyFDTable.FieldDefs.Update;
(If I change the TableName
property without calling this method, I get the same field definitions for each table).
When I use old BDE TTable
(through ODBC) the same method executes in 1 second.
Everything is getting much worse when the table has a BLOB
column with large data size. When the total table sizes 20 GiB this method executes 20 minutes for TFDTable
, and still one second for TTable
.
I suppose, FireDac does implicit Open
and FetchAll
during the FieldDefs.Update
, but why?
Here is an example of how I connect the PostgreSQL database:
- FireDac:
MyFDCon.Params.Add('DriverID=PG');
MyFDCon.Params.Add('Server=MyPgServerIP');
MyFDCon.Params.Add('Port=5432');
MyFDCon.Params.Add('Database=db1');
MyFDCon.Params.Add('CharacterSet=utf8');
MyFDCon.Connected := True;
MyFDTable.Connection := MyFDCon;
MyFDTable.TableName := MyTableName;
MyFDTable.FieldDefs.Update; //too slow for large tables
//populating field definitions:
for i := 0 to MyFDTable.FieldDefs.Count - 1 do
begin
...
end;
- BDE:
MyBdeTable.DatabaseName := MyODBCDSN;
MyBdeTable.TableName := MyTableName;
MyBdeTable.FieldDefs.Update; //very fast even for large tables
//populating field definitions:
for i := 0 to MyBdeTable.FieldDefs.Count - 1 do
begin
...
end;
So, my questions:
- Why does FireDac refresh the field definitions so slowly, comparing to BDE?
- Is there a way to speed up this call? Maybe some table options exist to control this?
- Is there another (faster) way to get the field definitions for the table without needing to query system tables?
P.S.:
- I cannot use BDE, because the solution must work for 64-bit too.
本文标签: delphiWhy is TFDTableFieldDefsUpdate so slowStack Overflow
版权声明:本文标题:delphi - Why is TFDTable.FieldDefs.Update so slow? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744774245a2624529.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论