The problem: I need to generate a 'unique string' for each row in a
table. I already use auto_increment for system dependencies between tables.
What is the best approach one of these or another?
After generating a candidate 'unique string' the two strategies that
came to mind are:
1. to then search the table's column to see if it is already assigned;
locking the table for write while searching and writing the new row, or
2. set the column to UNIQUE when defining the table. Just go ahead and
write the new row if you get a "non-unique" exception, generate another
'unique string' and try again.
I've tried both on a small XP laptop and get "lock timeout exceptions"
rather quickly using #1. But replace those with lots of re-writes when
there starts to get "collisions " of 'unique string's.
Any recommendations on approaches?
Thanks in advance,
Roy 6 1101
Roy Epperson wrote: I've tried both on a small XP laptop and get "lock timeout exceptions" rather quickly using #1. But replace those with lots of re-writes when there starts to get "collisions " of 'unique string's.
Any recommendations on approaches?
Use a better algorithm for generating unique strings. There are hashing
algorithms that are quite unlikely to generate collisions over a normal
sized set of data.
Try MD5() or SHA1(), which are both referenced with builtin functions in
MySQL. http://dev.mysql.com/doc/refman/5.0/...functions.html
Regards,
Bill K.
You are more likely to succeed if you use the data itself as a unique
key. If you are using a primary key, that would be considered a
"unique string". If this is coming in from a web server and you need
an additional unique id, you can always use the host generated
UNIQUE_ID.
using an auto-generated key on multiple tables can be very dangereous
if you do not have the proper referential integrity configured. In most
cases I have seen, the auto-incremented field is mostly useless on
child tables. That being said, the field should exist in both parent
and child tables, but should only be auto-increment in the parent - and
value must exist in Parent before inserting into a child -- know as a
Foreign Key.
PK example:
username -- should be the only part of a PK and should be unique by
itself - you can only have one username "myusername " You can have an
auto-increment userid#, but should NOT be a part of this PK.
Depending on what this is for, you should more than likely require the
services of a DBA that knows what he is doing... The great thing about
databases is that "anyone" can build one. The worst thing about
databases is that "anyone" can build one. The problem with most
database apps is that "anyone" built it.
You will never know how your db/app is going to perform until after
deployment and NO amount of hardware/file tuning will EVER correct a
bad database design. "But it worked in test (with only 50 rows) now,
with 1M rows performance really stinks"... DUH!
Thanks for the pointer. However, the unique key is not based on any
data in the table; just "picked out of the air". I don't understand how
MD5 or SHA1 might be used to generate a unique key without some input
data that is varing?
Bill Karwin wrote: Roy Epperson wrote:
I've tried both on a small XP laptop and get "lock timeout exceptions" rather quickly using #1. But replace those with lots of re-writes when there starts to get "collisions " of 'unique string's.
Any recommendations on approaches?
Use a better algorithm for generating unique strings. There are hashing algorithms that are quite unlikely to generate collisions over a normal sized set of data.
Try MD5() or SHA1(), which are both referenced with builtin functions in MySQL.
http://dev.mysql.com/doc/refman/5.0/...functions.html
Regards, Bill K.
Thanks for the comments.. I understand your points on keys. My "unique
key" is random set of non-whitespace to externally identify some info in
the db whose contents are not yet known when the record to the
information is created. on*******@first dbasource.com wrote: You are more likely to succeed if you use the data itself as a unique key. If you are using a primary key, that would be considered a "unique string". If this is coming in from a web server and you need an additional unique id, you can always use the host generated UNIQUE_ID.
using an auto-generated key on multiple tables can be very dangereous if you do not have the proper referential integrity configured. In most cases I have seen, the auto-incremented field is mostly useless on child tables. That being said, the field should exist in both parent and child tables, but should only be auto-increment in the parent - and value must exist in Parent before inserting into a child -- know as a Foreign Key.
PK example:
username -- should be the only part of a PK and should be unique by itself - you can only have one username "myusername " You can have an auto-increment userid#, but should NOT be a part of this PK.
Depending on what this is for, you should more than likely require the services of a DBA that knows what he is doing... The great thing about databases is that "anyone" can build one. The worst thing about databases is that "anyone" can build one. The problem with most database apps is that "anyone" built it.
You will never know how your db/app is going to perform until after deployment and NO amount of hardware/file tuning will EVER correct a bad database design. "But it worked in test (with only 50 rows) now, with 1M rows performance really stinks"... DUH!
Roy Epperson wrote: Thanks for the pointer. However, the unique key is not based on any data in the table; just "picked out of the air". I don't understand how MD5 or SHA1 might be used to generate a unique key without some input data that is varing?
Aha, thanks, I misunderstood what you were doing.
You might want to check out the UUID() function, which is designed to
generate a pseudo-random 128-bit number as a hex string, with a very low
probability of collisions. http://dev.mysql.com/doc/refman/5.0/...functions.html
Regards,
Bill K.
Better pointer!! Thanks Bill. I never thought to look there..
Bill Karwin wrote: Roy Epperson wrote:
Thanks for the pointer. However, the unique key is not based on any data in the table; just "picked out of the air". I don't understand how MD5 or SHA1 might be used to generate a unique key without some input data that is varing?
Aha, thanks, I misunderstood what you were doing.
You might want to check out the UUID() function, which is designed to generate a pseudo-random 128-bit number as a hex string, with a very low probability of collisions.
http://dev.mysql.com/doc/refman/5.0/...functions.html
Regards, Bill K. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: WKC |
last post by:
Recently, one of our database's mdf and ldf was corrupted. We were able to
bring back the database with the capability of importing and querying the
data. However, the data is not the full list. Some of the data are still
missing because the tables we want still has sone 'chain mis linkage' error
when we did a DBCC checkdb/checktable. DBCC couldn't fix those errors
either. We're pretty sure that there are some data still burry under the...
|
by: Dave Townsend |
last post by:
Hi,
Can anybody help me with the following piece of code?
The purpose behind the code is to parse HTML files, strip out
the tags and return the text between tags. This is part of a larger
application which will perform "searches" for text values in a
directory of html files, trying to match only the non-tagged text
in the documents.
|
by: nephish |
last post by:
Hey there,
kinda newbie question here.
i know how to read the lines of a txt file.
i know how to write a txt file.
but how do i overwrite a line value with another value ?
i mean, how do go to, say, line 3 of a text file and replace
what is written on line 3 with something else?
|
by: Prem K Mehrotra |
last post by:
I come from Oracle background. In Oracle, when one wants to do a point
in time
recovery, one can specify recover database until timestmap. Oracle's
database maps to a db2 subsystem, i.e., in Oracle database means
entire database, i.e.. all tablespaces (including indexes).
I see only recover tablespace and recover indexspace (or index)
commands in db2.
Therefore, one has to specify all the tablespaces and indexspaces and
recover them
|
by: apple |
last post by:
UDB v8 fp 6a on AIX 5.1.0.0
Below is a manual incremental recover from compressed backup datasets.
With external compress backup datasets, can it be coded to do an
automatic incremental recover? The manual incremental recover works
just fine, but having trouble getting the automatic incremental recover
to work. Thanks for your help
# INCREMENTAL BACKUP
| |
by: Ray Muforosky |
last post by:
Hello all:
Task: I want to do file search, using the "conatining text" option from
a web page.
How do I search for a file on my local drive containing a certain
string, from a web page. That is, how do run the windows search program
from a web page.
Any help will be appreciated.
|
by: gel |
last post by:
I would like to write some data recovery software as a learning thing.
The sort of thing that you would use to recover data from a currupt HDD
or floppy etc. I would like to be pointed in the right direction as
far as modules to use and suggested approaches.
|
by: Kent Feiler |
last post by:
If I understand the general direction of recent posts, the idea is to
improve the quality of html/css by soliciting help from the various
browsers. Browsers can certainly detect problems but they have no
sensible place to report them and no way to prevent the same problem
from happening over-and-over in multiple sites around the world. That
idea simply doesn't work.
But how about this one. Suppose we have all of those search engine...
|
by: mike_dba |
last post by:
I have been testing the db2 recover command on a DB2 V8.2 Linux
database. The database contains a single partition. I am not
archiving logs but retaining them on disk. the backup image is to
disk as well. I performed the following in order :
1. OFFLINE BACKUP <time#1>
2. Create table S.T (c1 smallint)
3. Insert several rows into S.T - values 1,2,3,4,5
4. ONLINE BACKUP <time#2>
5. Insert several more rows 6,7,8,9
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| | |