473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Indexes and string functions conditions

Hello !!
I have to tables (name A and B, B has a fulltext index). In need to
handle this type of query:

select A.* from A, B where Instr(A.field1,B.field2) and Match (B.text)
Against ('foo');

because field2 on B has a substring of the A.field1. Please note that
I have also an index on A.field1, and another on B.field2.

The issue is that I'm having too much time consuming process 'cos
Instr() doesn't seem to use the indexes, even using "force index"...
Any work around... any clue... ??

Thanks!

Sebastian.

Jul 20 '05 #1
3 1819
Sebastian Araya wrote:
The issue is that I'm having too much time consuming process 'cos
Instr() doesn't seem to use the indexes, even using "force index"...
Any work around... any clue... ??


Yes, this operation cannot benefit from an index.

Think of it this way: if I ask you to look up people in a telephone
book, and I'm looking for last names starting with "Stev", you can find
them pretty quickly because the book is alphabetized. But if I ask for
names where the string "stev" can occur anywhere in the name, you find
it harder to do the search and you have to search the whole book.

Bill K.
Jul 20 '05 #2
Hello Bill K,
thanks for the answer, but it's seems I didn't explain really good.

My problem is this: I'm searching for two conditions:

1. 'foo' in field text of table B, that's works fine using
fulltext index;
2. the leftmost string A.field1 which I like to match with
B.field2 (which I don't know really it's length so I
use Instr() ), but I have tried with:
B.field2 = left( A.field1, length( B.field2 ) )
allways getting the same results: it didn't use the indexes;

A little example may unoffuscate my problem: let A.field1 = 'ABCDEFG'
and B.field2 = 'ABC', and using B.field2 = left( A.field1, length(
B.field2 ) ), I think I don't break any index law, 'cos I'm looking for
starting strings.

So, forgive my uncleary exposure... then again, any clues ??
Sebastián.

Jul 20 '05 #3
nu*****@gmail.com wrote:
A little example may unoffuscate my problem: let A.field1 = 'ABCDEFG'
and B.field2 = 'ABC', and using B.field2 = left( A.field1, length(
B.field2 ) ), I think I don't break any index law, 'cos I'm looking for
starting strings.


Well, you may be looking for starting strings, but that's not what
INSTR() looks for. That function looks for a substring _anywhere_
inside the larger string, so it can't assume that you mean that the
string must occur at the start.

The other example you describe using LEFT() may not be able to use the
index on A.field1 because you're taking only part of the value that is
indexed. It'd be like indexing an integer column x and then searching
on "x MOD 100" or something.

Try this instead:

select A.* from A, B
where A.field1 LIKE CONCAT(B.field2, '%')
and Match (B.text) Against ('foo');

Bill K.
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris | last post by:
Any help would be appreciated. I am running a script that does the following in succession. 1-Drop existing database and create new database 2-Defines tables, stored procedures and functions...
16
by: Bhushit Joshipura | last post by:
This post contains one question and one proposal. A. May I know why order of evaluation of arguments is not specified in C/C++? I asked a question in comp.lang.c++ for the following...
9
by: Igor | last post by:
Is there a way to force optimizer to use indexes without hints? (some server setting or index type...) I'll give an example to clarify : I have a table with fields Customer_Code char(10) not...
4
by: Jonathan Burd | last post by:
Greetings everyone, Here is a random string generator I wrote for an application and I'm wondering about the thread-safety of this function. I was told using static and global variables cause...
8
by: jake1138 | last post by:
Maybe this is a newbie thing and everyone already knows how to do this, but I figured I'd post these functions anyway in case someone finds them useful. I used Jack Klein's example (see link...
5
by: Shiraz | last post by:
Is there some manual on how to make indexes? for example: table is create mytable ( a varchar, b varchar, c int, d int
2
by: Lyle Fairfield | last post by:
'Property Clustered As Boolean 'Member of DAO.Index Private Sub IsThereaClusteredIndex() Dim tdf As DAO.TableDef Dim idx As DAO.Index For Each tdf In DBEngine(0)(0).TableDefs For Each idx In...
4
by: gfrith | last post by:
Hi, A quick regex question which I've worked around for the time being, but would like an answer to if anyone can help. I want to match on all strings which end _id, but not those ending...
17
by: mac | last post by:
Hi, I'm trying to write a fibonacci recursive function that will return the fibonacci string separated by comma. The problem sounds like this: ------------- Write a recursive function that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.