473,385 Members | 1,356 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,385 software developers and data experts.

I can get Substring to work, but how does it work below the surface...

In a perl script, I'm reading in data from a mysql server database that has some fields that could be millions of bytes long (DNA sequences). However, I am interested only in the first 1000 or so bases (characters) - and I already know how to use SUBSTRING() to select those.

My question deals more with performance: How does SUBSTRING() actually work? I don't want to read in the whole field, then take a portion of it to get my end result, because reading in the rest of the field is just wasted time/effort. And when I only want 1000 bases out of millions, that's a lot of wasted time. Since locally I don't have the string already saved, does the mysql SUBSTRING command (within a larger SELECT statement) get all of the field, or does it find the beginning and just read up to what I've specified.

Any suggestions for other ways around this problem?

I'm running an openSUSE Linux distribution, if that's relevant at all.

Thanks
Jun 21 '07 #1
2 1638
Atli
5,058 Expert 4TB
Well, I'd imagine that MySQL just gets the part of the string you want, but there is not way I can be sure.

If you have millions of bytes in some table, you can easilly test it.
Just do a query that fetches like 1/4 of each field in a number of rows, then do the same with the whole fields and measure the difference.
The first test should only take 1/4'th the time of the second test.
Jun 23 '07 #2
pbmods
5,821 Expert 4TB
Heya, falconite.

I'm assuming that your fields are TEXTs, which means that you have to specify an index length. As long as you are indexing at least the first 1000 (or so) characters, your queries should execute reasonably quickly.

You may need a hard drive the size of a planet, but your queries should execute fairly quickly :)

You can alternatively use LEFT(). Not sure if it's any faster than SUBSTRING(), but I would presume that it would save a couple of instructions b/c MySQL wouldn't have to check to see if the starting index is 0.
Jun 23 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Patrick Fisher | last post by:
Hi All The function below is intended to create a table called tblNewTable which is a copy of tblProducts in another database, the name of the database is held in strFileName. The problem is...
6
by: becte | last post by:
I am little bit confused Is this a legal way of removing a substring from a string? What about the second alternative using strcpy, is it ok even though the source and dest. strings overlap? ...
11
by: Nick | last post by:
This is really starting to piss me off. Someone please prove me wrong. Here is a link to the function in DX 9 sdk....
2
by: Philipp Sumi | last post by:
Hello Newsgroup I'm using a simple Regex expression to extract placeholders enclosed in "_" from a string as below: string pattern = @"_(\S+)_"; string test1 = "the _first_ and the _second_...
2
by: Michele Fondry via .NET 247 | last post by:
hello. I have a webform form app in vb.Net that uses a SQL query. I am trying to use the substring function, but get the following error: Description: An unhandled exception occurred during the...
1
by: db55 | last post by:
This script doesn't work. Why? UPDATE SET = LTRIM(SUBSTRING(, 1, convert(bigint, CHARINDEX(',', Comments)-1))) WHERE NOT( IS NULL) AND LEN() > 8 Basically, I'm trying to...
6
by: kellygreer1 | last post by:
What is a good one line method for doing a "length safe" String.Substring? The VB classes offer up the old Left function so that string s = Microsoft.VisualBasic.Left("kelly",200) // s will =...
2
by: intrader | last post by:
Looking at the watch window, I have ----------------watch window----------------------- ix 6 int tStr "hyphen, and )(*" string tStr.Substring(0,ix) error:'tStr.Substring' does not...
3
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
Two part question: 1. Is Regex more efficient than manually comparing values using Substring? 2. I've never created a Regex expression. How would I use regex to do the equivalent of what I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.