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 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old February 23rd, 2008, 11:47 AM
EvilGuru EvilGuru is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 141 EvilGuru User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 14 h 7 m 17 sec
Reputation Power: 4
Indexing TEXT

I am porting my application which is currently Postgres/MySQL/SQLite over to Firebird and am having a bit of trouble finding a replacement for the TEXT type.

I have a type, answers, with an integer ID and some text. Normally this is implemented using the TEXT type with an index on the column (in the case of MySQL this is on the first 50 bytes).

Firebird does not have a TEXT type, however, and the BLOB sub-type which is recommended for storing TEXT can not be indexed. Although large (32k) varchar columns are supported, I can not find a way of only indexing the first few (50 or so) bytes. Of-course a 32k index is not practical. I have also read that a 32k varchar column is 500+2 bytes when empty.

So I am unsure what to do. I need to remain SQL compatible (so SELECT id FROM answers WHERE response = 'foo') and need 10,000 actual characters of space. What should I do?

Expression indexes looked promising, but would probably require changes to my SELECT query.

Regards, Freddie.

Reply With Quote
  #2  
Old February 24th, 2008, 04:41 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,686 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 5 Days 16 h 27 m 51 sec
Reputation Power: 259
Quote:
Originally Posted by EvilGuru
...
Expression indexes looked promising, but would probably require changes to my SELECT query.
...
Uh? Why do you think this? It will make explicitly what MySQL makes behind the scenes (as usual ...)
Let me add that I don't see the point of indexing a text/blob field, unless you are using a full-text index, which unfortunately is not supported by Firebird.

Reply With Quote
  #3  
Old February 24th, 2008, 07:07 AM
EvilGuru EvilGuru is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 141 EvilGuru User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 14 h 7 m 17 sec
Reputation Power: 4
Quote:
Uh? Why do you think this? It will make explicitly what MySQL makes behind the scenes (as usual ...)
Let me add that I don't see the point of indexing a text/blob field, unless you are using a full-text index, which unfortunately is not supported by Firebird.

If I added an index on HASH(response) then my query would now become (using a varchar for the TEXT):
Code:
SELECT id FROM answers WHERE HASH(:val) = HASH(response) AND :val = response

Since I doubt Firebird would automatically use the index for :val = response. So I would need to change my SQL adding an exception case for Firebird.

The reason for this table is that my database works in terms of id's, while users work in terms of text. Therefore I need to translate between the two. Hence the need to index the column.

Regards, Freddie.

Reply With Quote
  #4  
Old February 25th, 2008, 01:37 PM
clivew clivew is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 703 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 16 h 44 m 49 sec
Reputation Power: 12
Quote:
Since I doubt Firebird would automatically use the index for :val = response.

I don't actually know the answer; but why don't you set up a test instead of making assumptions?
Instinctively, there would seem little benefit in suporting an expression index if it is not used by SQL.

Another option might be to add a column that uses the first x characters of the VARCHAR column and is maintained by insert and update triggers.

Clive
Comments on this post
pabloj agrees!

Last edited by clivew : February 25th, 2008 at 01:40 PM.

Reply With Quote
  #5  
Old February 26th, 2008, 10:18 AM
EvilGuru EvilGuru is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 141 EvilGuru User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 14 h 7 m 17 sec
Reputation Power: 4
Quote:
Originally Posted by clivew
I don't actually know the answer; but why don't you set up a test instead of making assumptions?
Instinctively, there would seem little benefit in suporting an expression index if it is not used by SQL.

It would appear my assumption is correct:
Code:
SQL> SELECT id FROM test WHERE response = '42';

PLAN (TEST NATURAL)
SQL> SELECT id FROM test WHERE HASH(response) = HASH('42');

PLAN (TEST INDEX (IDX_TEST_RESP))


Quote:
Another option might be to add a column that uses the first x characters of the VARCHAR column and is maintained by insert and update triggers.

I think that would also require me to change my SQL (so that it first tests the indexed column and then the main one).

It looks as if I am going to have to have a special case for firebird and use a different SELECT query for it.

Regards, Freddie.

Reply With Quote
  #6  
Old February 26th, 2008, 02:22 PM
clivew clivew is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 703 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 16 h 44 m 49 sec
Reputation Power: 12
Can you clarify for me?
Do you want an exact match on the text; but you want an expression index on the first 50 chars to speed the query or do you want all records where the first 50 chars are a match?

Clive

Last edited by clivew : February 26th, 2008 at 02:30 PM. Reason: Changed message

Reply With Quote
  #7  
Old February 26th, 2008, 03:04 PM
EvilGuru EvilGuru is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 141 EvilGuru User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 14 h 7 m 17 sec
Reputation Power: 4
Quote:
Originally Posted by clivew
Can you clarify for me?
Do you want an exact match on the text; but you want an expression index on the first 50 chars to speed the query or do you want all records where the first 50 chars are a match?

No problem

I only need exact matches. Only reason I said around 50 chars is because indexing the entire field is not possible (as it goes over the maximum index size) and 50 chars should narrow the possibilities down significantly.

I would like an index which allows for:
Code:
SELECT id FROM answers WHERE response = 'textual value';

Where response is a moderately sized varchar column (too large to be indexed in its entirety). A HASH expression index would work, but would require me to add an exceptional case in my application for this (as a different query is required).

Regards, Freddie.

Reply With Quote
  #8  
Old February 26th, 2008, 03:55 PM
clivew clivew is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 703 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 16 h 44 m 49 sec
Reputation Power: 12
Quote:
A HASH expression index would work, but would require me to add an exceptional case in my application for this (as a different query is required).

Personally that is what I would (and typically do) do.

There are so many variations in SQL and Stored Procedure language between databases that, when I have an application that must talk to more than one, I encapsulate all the database access and make sure the rest of my program is ignorant of the specific back end.

IMO that is the best way to both maintain one set of general program code and take advantage of the specific strengths of each database back end.

Clive

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > Indexing TEXT


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway