Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
« Previous Thread | Next Thread » Featured Thread Featured Thread  
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old February 20th, 2007, 03:06 AM
miztaken miztaken is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 24 miztaken User rank is Private First Class (20 - 50 Reputation Level)miztaken User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 13 h 7 m 22 sec
Reputation Power: 0
Post EXTERNAL TABLES IN Firebird

Hi,
After i knew there is not Bulk insert methods in FB.
I tried Prepared statements and also partial committing of transaction.
This saved me a lot of time but now even it is slow..
Then i heard that dumping the data into simple table and then creating ENTERNAL TABLE from it and then finally adding the data into database will be even more faster.
So i stared, and got stuck ..
I did it like this...

I'm developing an application in C#.net

TextWriter trwiter = new StreamWriter(@"C:\ExternalTables\Ext.ext", false, Encoding.ASCII);
for (int i = 0; i < 11; i++)
trwiter.WriteLine(i);
trwiter.Close();

Like this i dumped my stuffs in simple file named Ext.ext.
Then i created a database in FB and created an EXTERNAL TABLE like this:

command.CommandText = @"CREATE TABLE TEMP1 EXTERNAL FILE 'c:\ExternalTables\Ext.ext'(ID INTEGER,CRLF CHAR(2));";
int j=command.ExecuteNonQuery();

After doing this, when i fetched data from this table like this:
command.CommandText = "SELECT ID FROM TEMP1;";
FbDataReader reader= command.ExecuteReader();
while (reader.Read())
{
int iii = reader.Getint32(0);
}
And the outputs were:
822742320
856296754
889851188
923405622
...
..
and so on..
I dont know what am i missing..
Please help me...
I am in real need of this..

Reply With Quote
  #2  
Old February 20th, 2007, 10:43 AM
clivew clivew is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 712 clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 17 h 46 m 13 sec
Reputation Power: 12
Quote:
Originally Posted by miztaken
I'm developing an application in C#.net

TextWriter trwiter = new StreamWriter(@"C:\ExternalTables\Ext.ext", false, Encoding.ASCII);
for (int i = 0; i < 11; i++)
trwiter.WriteLine(i);
trwiter.Close();

Like this i dumped my stuffs in simple file named Ext.ext.
Then i created a database in FB and created an EXTERNAL TABLE like this:

command.CommandText = @"CREATE TABLE TEMP1 EXTERNAL FILE 'c:\ExternalTables\Ext.ext'(ID INTEGER,CRLF CHAR(2));";
int j=command.ExecuteNonQuery();

After doing this, when i fetched data from this table like this:
command.CommandText = "SELECT ID FROM TEMP1;";
FbDataReader reader= command.ExecuteReader();
while (reader.Read())
{
int iii = reader.Getint32(0);
}
And the outputs were:
822742320
856296754
889851188
923405622
...
..
and so on..
I dont know what am i missing..
Please help me...
I am in real need of this..

What does Ext.ext look like in a text editor and in a Hex editor?

Reply With Quote
  #3  
Old February 20th, 2007, 11:07 PM
miztaken miztaken is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 24 miztaken User rank is Private First Class (20 - 50 Reputation Level)miztaken User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 13 h 7 m 22 sec
Reputation Power: 0
Quote:
Originally Posted by clivew
What does Ext.ext look like in a text editor and in a Hex editor?

In wordpad,
0
1
2
3
4
5
6
7
8
9
10

In Hex Editor
300D0A310D0A320D0A330D0A340D0A350D0A360D0A370D0A380D0A390D0A31300D0A

Any Clues...
Please Help

Reply With Quote
  #4  
Old February 20th, 2007, 11:44 PM
clivew clivew is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 712 clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 17 h 46 m 13 sec
Reputation Power: 12
OK. So now we know you are creating the file as you intend.

Now what happens if you simply issue the SQL against the table in isql or some other database GUI like ibExpert?

If you get garbage then there is something wrong with the way you
are defining the external table in C#.

If it is not garbage, then there is something wrong with the way
you are reading the data in C#.

I am not a C# programmer, so I can only suggest ways you narrow your focus to the actual issue.

Clive.
Comments on this post
pabloj agrees!

Reply With Quote
  #5  
Old February 21st, 2007, 03:44 AM
miztaken miztaken is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 24 miztaken User rank is Private First Class (20 - 50 Reputation Level)miztaken User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 13 h 7 m 22 sec
Reputation Power: 0
Quote:
Originally Posted by clivew
OK. So now we know you are creating the file as you intend.

Now what happens if you simply issue the SQL against the table in isql or some other database GUI like ibExpert?

If you get garbage then there is something wrong with the way you
are defining the external table in C#.

If it is not garbage, then there is something wrong with the way
you are reading the data in C#.

I am not a C# programmer, so I can only suggest ways you narrow your focus to the actual issue.

Clive.

Hi there,
I found where i was wrong..
It was all due to UNICODE..( damn, i should have thought of that previously)
Now i converted from UNICODE to ASCII char array, and dumped in the file. Then i fetched from file type casted and inserted it on my real table.
It worked but i still have to explore the performance.
Thanks for all the suggestions..
I will post the preformance crapps later.
Take Care
Bye
Comments on this post
pabloj agrees!

Reply With Quote
  #6  
Old February 22nd, 2007, 01:10 AM
miztaken miztaken is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 24 miztaken User rank is Private First Class (20 - 50 Reputation Level)miztaken User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 13 h 7 m 22 sec
Reputation Power: 0
Okai, Now i'm really in trouble.
This insertion process is getting over my head now.

First i tried simple insertion, it was obviously too too slow.
Then i used prepared statements, things started getting little bit faster.
Then again i used prepared statements with Transaction.CommitRetaining() and it was beneficial too..

Than i heard about EXTERNAL TABLE and EXTERNAL Files.
Searched whole day about it, made it work and implemented it.
First i dumped my stuffs in a text file. Then i made table using this file as EXTERNAL File.
Then i dumped it from that table to my desired table (i removed index from table while dumping it and then recreated index.)
Now the problems were:
1. When i dump my things into text files. It requires hugh space. Nevermind i can manage space. But since all the data type have to be converted to CHAR types to store into EXTERNAL TABLE so i have to convert all my types into fixed length CHARs and then attach to external tables.
Now after i created the external table,
select * from ext_table
while(reader.read())
{
(a) getvalues
(b) typecast it
(c) insert into my real table.
}
This whole process is taking much time than expected.
Dumping to file happens to be fast. But dumping from external table to my database table is very slow.
2. Also deleting and recreating index consumes time.

Can anyone please suggest me any thing...
I've heard "EXTERNAL TABLES are the fastest way you can insert" but its behaving slow.
I must have missed something..
I am in real need of some advice from you people...
Thanks in advance...

Reply With Quote
  #7  
Old February 22nd, 2007, 05:09 AM
miztaken miztaken is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 24 miztaken User rank is Private First Class (20 - 50 Reputation Level)miztaken User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 13 h 7 m 22 sec
Reputation Power: 0
Okai, Finally i fgured out how to do the thing but got stuck in another error..

I did it like this:

1. Create EXTERNAL TABLE (TEMP1) with the file (dump.txt) i have dumped.
2. Then i inserted values in my original table (tb1) like
INSERT INTO tb1 SELECT col1,col2 .. from TEMP1;
But while executing this query i got following problem after few minutes....
I/O error for file fseek "D:\TEMP\dump.txt" Error while trying to open file.

Info: My dump.txt file is almost 3 GB.

Is it memory issue i mean.. due to low memory.
Or is it something else..

Reply With Quote
  #8  
Old February 22nd, 2007, 08:29 AM
miztaken miztaken is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 24 miztaken User rank is Private First Class (20 - 50 Reputation Level)miztaken User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 13 h 7 m 22 sec
Reputation Power: 0
Quote:
Originally Posted by miztaken
Okai, Finally i fgured out how to do the thing but got stuck in another error..

I did it like this:

1. Create EXTERNAL TABLE (TEMP1) with the file (dump.txt) i have dumped.
2. Then i inserted values in my original table (tb1) like
INSERT INTO tb1 SELECT col1,col2 .. from TEMP1;
But while executing this query i got following problem after few minutes....
I/O error for file fseek "D:\TEMP\dump.txt" Error while trying to open file.

Info: My dump.txt file is almost 3 GB.

Is it memory issue i mean.. due to low memory.
Or is it something else..

Hehe i found the solution that there is no solution..
The maximum external file size supported by FB is 2GB
Thanks anyways to all..

Reply With Quote
  #9  
Old February 22nd, 2007, 12:47 PM
clivew clivew is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 712 clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 17 h 46 m 13 sec
Reputation Power: 12
Quote:
Originally Posted by miztaken
Hehe i found the solution that there is no solution..
The maximum external file size supported by FB is 2GB
Thanks anyways to all..

Is there no way you can split the data into multiple files of less than 2GB each?

Clive

Reply With Quote
  #10  
Old February 22nd, 2007, 11:28 PM
miztaken miztaken is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 24 miztaken User rank is Private First Class (20 - 50 Reputation Level)miztaken User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 13 h 7 m 22 sec
Reputation Power: 0
Quote:
Originally Posted by clivew
Is there no way you can split the data into multiple files of less than 2GB each?

Clive

Yes i can split it.. and i am doing it right now..
But guess it will take some additional steps.. but its acceptable..
I have deployed it successfully, and testing its performance..
Lets see that will happen..
Anyways, thanks for all the concern.
Quite Active and Excellent Forum,this is, i must admit
Take Care

Reply With Quote
  #11  
Old March 26th, 2008, 10:38 AM
Cesar_evn Cesar_evn is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 1 Cesar_evn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 37 sec
Reputation Power: 0
How to split a external table

Quote:
Originally Posted by miztaken
Yes i can split it.. and i am doing it right now..
But guess it will take some additional steps.. but its acceptable..
I have deployed it successfully, and testing its performance..
Lets see that will happen..
Anyways, thanks for all the concern.
Quite Active and Excellent Forum,this is, i must admit
Take Care



Hi

How did you split the external table in several files? I'm using a external table but it is almot 2G and I need to add more records.

I'm triying but I don't find the command to do it. I used a commnand similar to the one I use to split database in several files.

Thanks

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > EXTERNAL TABLES IN Firebird


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |