![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi all, I need to work through a master and its details table. My first attempt was to open a DataReader on the master and for each record get a new DataReader on the detail, restricted to the foreign key. But this is very slow. As the tables are very large I cannot use DataSet's functionality. So my idea was to use a stored procedure for the detail reader that returns details in the same order as the master. 1) Can this be done with a stored procedure? How? 2) Is there a better way? Thanks for any advice, Christian details.read(); while (master.Read()) { int key = master.GetInt32(masterPrimaryKeyCol); while (details.GetInt32(detailForeignKeyCol) == key) { // process details // ... details.read(); } // while details } // while master |
#3
| |||
| |||
|
|
Hi all, I need to work through a master and its details table. My first attempt was to open a DataReader on the master and for each record get a new DataReader on the detail, restricted to the foreign key. But this is very slow. As the tables are very large I cannot use DataSet's functionality. So my idea was to use a stored procedure for the detail reader that returns details in the same order as the master. 1) Can this be done with a stored procedure? How? 2) Is there a better way? Thanks for any advice, Christian details.read(); while (master.Read()) { int key = master.GetInt32(masterPrimaryKeyCol); while (details.GetInt32(detailForeignKeyCol) == key) { // process details // ... details.read(); } // while details } // while master |
#4
| ||||
| ||||
|
|
What are you trying to actually accomplish? |
|
If you have a lot of rows, then it will take time. |
|
You can sort the detail data using the same sort as the master day, so all the details rows for master 1 will be first, followed by all detail records for 2, and so on. |
|
"Christian Schmidt" <none (AT) locom (DOT) de> wrote in message news:uNPrZSdzGHA.1288 (AT) TK2MSFTNGP03 (DOT) phx.gbl... Hi all, I need to work through a master and its details table. My first attempt was to open a DataReader on the master and for each record get a new DataReader on the detail, restricted to the foreign key. But this is very slow. As the tables are very large I cannot use DataSet's functionality. So my idea was to use a stored procedure for the detail reader that returns details in the same order as the master. 1) Can this be done with a stored procedure? How? 2) Is there a better way? Thanks for any advice, Christian details.read(); while (master.Read()) { int key = master.GetInt32(masterPrimaryKeyCol); while (details.GetInt32(detailForeignKeyCol) == key) { // process details // ... details.read(); } // while details } // while master |
#5
| |||
| |||
|
|
Hi Marina, thanks for your interest. What are you trying to actually accomplish? I need to do calculations (that cannot be expressed in SQL) on master detail structures, e.g. given a set of shipments (~1E6) with containers (~5E6), I need to determine which of these shipments fit on which transporter. If you have a lot of rows, then it will take time. Running through the records with a DataReader takes acceptable time (using SqlConnection to a SQL 2000 Server). What does not take acceptable time is opening a DataReader on the details for each master record. So that's why my idea is to run through the details in the same order (regarding the foreign key) as the master's primary key occur. You can sort the detail data using the same sort as the master day, so all the details rows for master 1 will be first, followed by all detail records for 2, and so on. That's exactly what I want, but: The select-statement for the master has already an order by, so I cannot simply sort the details by the foreign key. Any ideas? Cheers, Christian "Christian Schmidt" <none (AT) locom (DOT) de> wrote in message news:uNPrZSdzGHA.1288 (AT) TK2MSFTNGP03 (DOT) phx.gbl... Hi all, I need to work through a master and its details table. My first attempt was to open a DataReader on the master and for each record get a new DataReader on the detail, restricted to the foreign key. But this is very slow. As the tables are very large I cannot use DataSet's functionality. So my idea was to use a stored procedure for the detail reader that returns details in the same order as the master. 1) Can this be done with a stored procedure? How? 2) Is there a better way? Thanks for any advice, Christian details.read(); while (master.Read()) { int key = master.GetInt32(masterPrimaryKeyCol); while (details.GetInt32(detailForeignKeyCol) == key) { // process details // ... details.read(); } // while details } // while master |
#6
| |||
| |||
|
|
I guess it all depends on your query for the detail data. You must be joining on the primary key of the master - so why not sort on that for both result sets. |
|
Opening a datareader isn't what isn't acceptable. It is the time to run the query - that is what opening a datareader is. So if your query takes too long, then perhaps you need to optimize it so it runs faster, or make sure you have the right indexes on your tables, etc. |
#7
| |||
| |||
|
|
Rules for an efficient application: 1) Do not recreate (download) the entire database or entire tables to the client. 2) See 1. |
|
When working with relational databases we use the SQL engine to return relational "products" from SELECT statements that use the JOIN operator to build correlated sets of rows--some columns drawn from several related tables. |
|
While the ADO.NET DataSet/DataTable approach appears to mimic this, it only works efficiently if you return a small subset of the rows to the DataTable. Sure, you can use the DataReader but why? The DataAdapter Fill method can return selected rows from several tables in a single operation if you aren't accessing JET. |
#8
| |||
| |||
|
|
Hi Marina, thanks for your interest. What are you trying to actually accomplish? I need to do calculations (that cannot be expressed in SQL) on master detail structures, e.g. given a set of shipments (~1E6) with containers (~5E6), I need to determine which of these shipments fit on which transporter. If you have a lot of rows, then it will take time. Running through the records with a DataReader takes acceptable time (using SqlConnection to a SQL 2000 Server). What does not take acceptable time is opening a DataReader on the details for each master record. So that's why my idea is to run through the details in the same order (regarding the foreign key) as the master's primary key occur. You can sort the detail data using the same sort as the master day, so all the details rows for master 1 will be first, followed by all detail records for 2, and so on. That's exactly what I want, but: The select-statement for the master has already an order by, so I cannot simply sort the details by the foreign key. Any ideas? Cheers, Christian "Christian Schmidt" <none (AT) locom (DOT) de> wrote in message news:uNPrZSdzGHA.1288 (AT) TK2MSFTNGP03 (DOT) phx.gbl... Hi all, I need to work through a master and its details table. My first attempt was to open a DataReader on the master and for each record get a new DataReader on the detail, restricted to the foreign key. But this is very slow. As the tables are very large I cannot use DataSet's functionality. So my idea was to use a stored procedure for the detail reader that returns details in the same order as the master. 1) Can this be done with a stored procedure? How? 2) Is there a better way? Thanks for any advice, Christian details.read(); while (master.Read()) { int key = master.GetInt32(masterPrimaryKeyCol); while (details.GetInt32(detailForeignKeyCol) == key) { // process details // ... details.read(); } // while details } // while master |
#9
| |||
| |||
|
|
If the calculations are too hard for TSQL, write a CLR executable (in any CLR language including VB.NET) to handle the computations and do them in-situ on the server. Your performance should soar. This is what CLR functions and sps are for. |
#10
| |||
| |||
|
|
Hi William, If the calculations are too hard for TSQL, write a CLR executable (in any CLR language including VB.NET) to handle the computations and do them in-situ on the server. Your performance should soar. This is what CLR functions and sps are for. Can these CLR executables be uploaded during runtime? Do you have some good weblinks on this stuff? Will it work for the express/MSDE editions, too? So for data-intensive calculations you would advise against multi-tier? Thank you very much fo your patience :-) |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |