Re: #1005 - Can't create table '.\unb2test\#sql-770_2.frm' (errno: 150)

2008-03-15 Thread Yves Goergen

On 14.03.2008 00:55 CE(S)T, Rob Wultsch wrote:

I am guessing it is an issue with SearchRevision being an INTEGER,
and  RevisionNumber being a SMALLINT.


Thank you, that was the problem. My design was incorrect anyway to use 
different types here... Now that's fixed, too. :)



http://www.google.com/search?q=150+error+mysql yields
http://bugs.mysql.com/bug.php?id=6188 as it's first result.


Not so in Germany. ;) Also, I've searched for a more specific message. 
Must have missed it.


--
Yves Goergen LonelyPixel [EMAIL PROTECTED]
Visit my web laboratory at http://beta.unclassified.de

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



how to use index with order by here

2008-03-15 Thread Nacho Garcia
Hi, im having troubles with one query, hope someone can help.

on this table:

messages:
id_fromint(10)
id_toint(10)
textvarchar(1000)
time

with index on id_form and id_to

i want to get messages sent from one user to another and vice versa order by
time.
let say we want to search messages between user 1 and 2:
i'm doing:

SELECT *
FROM messages
WHERE id_from in (1,2)
AND id_to in (1,2)
ORDER BY time

but that gives me a filesort in all rows matching the where clause, and
thats not good. I tried by indexing id_from, id_to, time but thats not
working of course.

any help would be really appreciate.


Re: how to use index with order by here

2008-03-15 Thread Rob Wultsch
On Sat, Mar 15, 2008 at 2:42 PM, Nacho Garcia [EMAIL PROTECTED] wrote:
 Hi, im having troubles with one query, hope someone can help.

  on this table:

  messages:
  id_fromint(10)
  id_toint(10)
  textvarchar(1000)
  time

  with index on id_form and id_to

  i want to get messages sent from one user to another and vice versa order by
  time.
  let say we want to search messages between user 1 and 2:
  i'm doing:

  SELECT *
  FROM messages
  WHERE id_from in (1,2)
  AND id_to in (1,2)
  ORDER BY time

  but that gives me a filesort in all rows matching the where clause, and
  thats not good. I tried by indexing id_from, id_to, time but thats not
  working of course.

  any help would be really appreciate.


Short answer: The filesort is not necessary not your problem. Add a
composite key on  id_from,id_to.
ALTER TABLE `messages` ADD INDEX ( `id_from` , `id_to` )

Long answer
http://dev.mysql.com/doc/refman/5.0/en/order-by-optimization.html
In some cases, MySQL cannot use indexes to resolve the ORDER BY,
although it still uses indexes to find the rows that match the WHERE
clause. These cases include the following:
...
The key used to fetch the rows is not the same as the one used in the ORDER BY:
SELECT * FROM t1 WHERE key2=constant ORDER BY key1;

As a quick example using your table I will generate a bunch of data to
play with:
DROP TABLES IF EXISTS messages,integers,user_ids;

CREATE TABLE integers(i int NOT NULL PRIMARY KEY);
INSERT INTO integers(i) VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9);

CREATE TABLE user_ids(`id` int(10))
SELECT t.i * 10 + u.i as id
FROM integers AS u, integers as t
WHERE (t.i * 10 + u.i)  100;

CREATE TABLE `messages` (
  `id_from` int(10) NOT NULL,
  `id_to` int(10) NOT NULL,
  `text` varchar(1000) NOT NULL,
  `time` datetime NOT NULL
);

INSERT INTO messages(id_from, id_to,text,time)
SELECT t1.id, t2.id, '',NOW()
FROM user_ids t1, user_ids t2;

INSERT INTO messages(id_from, id_to,text,time)
SELECT t1.id, t2.id, '',DATE_SUB(NOW( ), INTERVAL 1 DAY)
FROM user_ids t1, user_ids t2;

INSERT INTO messages(id_from, id_to,text,time)
SELECT t1.id, t2.id, '',DATE_SUB(NOW( ), INTERVAL 2 DAY)
FROM user_ids t1, user_ids t2;

INSERT INTO messages(id_from, id_to,text,time)
SELECT t1.id, t2.id, '',DATE_SUB(NOW( ), INTERVAL 3 DAY)
FROM user_ids t1, user_ids t2;

INSERT INTO messages(id_from, id_to,text,time)
SELECT t1.id, t2.id, '',DATE_SUB(NOW( ), INTERVAL 5 DAY)
FROM user_ids t1, user_ids t2;

INSERT INTO messages(id_from, id_to,text,time)
SELECT t1.id, t2.id, '',DATE_SUB(NOW( ), INTERVAL 6 DAY)
FROM user_ids t1, user_ids t2;

INSERT INTO messages(id_from, id_to,text,time)
SELECT t1.id, t2.id, '',DATE_SUB(NOW( ), INTERVAL 7 DAY)
FROM user_ids t1, user_ids t2;

This creates 70k rows.

Without an index your query takes  ~.25 sec on a rather slow box and
examines 70k rows.
With an index on id_from your query takes  ~.01 sec and examines 1.4k rows.
With a composite index on id_from,id_to your query takes  ~.002 sec
and examines 28 rows, and has a filesort. Still pretty fast...


-- 
Rob Wultsch

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



db design

2008-03-15 Thread Brett Harvey

which method is better to do.

I have 5 tables.  They represent sections/parts of a companies 
standards.  There are 13 main categories, each of those categories 
has subsections (some with 3, some with 10 or more), those 
subsections have subsections, etc.


Which table design is better to do.

Table A
ID
Std_no
Name

Table B
ID
table_a_id
Std_no
Name

Table C
ID
table_b_id
Std_no
Name

Table D
ID
table_c_id
Std_no
Name

Table E
ID
table_d_id
Std_no
Name

In this case, each table links back to the one before it. via the unique ID

OR

Table A
std_a
Name

Table B
std_a
std_b
Name

Table C
std_a
std_b
std_c
Name

Table D
std_a
std_b
std_c
std_d
Name

Table E
std_a
std_b
std_c
std_d
std_e
Name

In this case, additional fields are used and all pieces linking to 
the previous part of the standard are used.




This will be used in a web app.  Cascading Drop down boxes will be 
used and a person will select the standard.
Thus, they select Item 3 from table A, selection box B has only items 
related to from table A that are related to Item 3. They select from 
selection box c which may (or may not) have items related to what was 
in table B.




I hope this makes sense.  Hard to diagram it here.


Thanks!

Brett



--

/Brett C. Harvey;
/Creative-Pages.Net, President;
/Facility Management Systems, CTO (www.waldo.com/www.fmsystems.biz);
/Lasso Professional Alliance Member ID #LPA135259 (www.lassosoft.com);


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]