Re: open files in mysqld 5.1.53

2013-06-12 Thread Reindl Harald


Am 12.06.2013 12:03, schrieb walter harms:
 i am trying to understand the incredible use of filepointers in our mysql 
 server (5.1.53).
 under normal condition the server reports 10k-15k open files pointer

harmless :-)

[root@localhost:~]$ lsof | grep mysqld | wc -l
471206

nobody but oracle knows why there are so much file handles
and this is MySQL 5.5.32

[--] Data in MyISAM tables: 481M (Tables: 4861)
[OK] Highest usage of available connections: 6% (32/500)
[OK] Thread cache hit rate: 99% (32 created / 425K connections)



signature.asc
Description: OpenPGP digital signature


Re: open files in mysqld 5.1.53

2013-06-12 Thread Manuel Arostegui
2013/6/12 walter harms wha...@bfs.de


 Hi list,
 i am trying to understand the incredible use of filepointers in our mysql
 server (5.1.53).
 under normal condition the server reports 10k-15k open files pointer.
 I run a 'flush tables' every 2h to avoid problems, the number of
 users/connections is constant
 It is an automatic system but a few human users, a happy mix of myisam and
 innodb tables running
 with no problems on  mysqld 5.0 . But now sometimes i am
 hit with an insane increase hitting the ceiling at 60k. I do not like the
 idea to increase the
 limit further because i do
 not understand why this is happening (I seems to happen at random times).

 I am running out of idea what my cause the unexpected increase, any idea
 what to watch ?


I had a similar problem some years ago with 5.0.84. It was a database with
thousand of tables (mostly in MyISAM).
It turned to be the  --myisam-recover option in Debian init scripts (
/usr/share/mysql/debian-start.inc.sh) . Obviously it's not a good idea to
remove it, as if the server crashes, you will needed it.
This used to be our db server after getting started:

dXX:~# find /proc/`cat /var/run/mysqld/mysqld.pid`/fd -follow -type f
2/dev/null | wc -l
116810

This is what I saw at the time after removing that MyISAM check:

dXX:~# find /proc/`cat /var/run/mysqld/mysqld.pid`/fd -follow -type f
2/dev/null | wc -l
10730

I would not recommend to keep this as a for-good-solution but a temporary
one till you decide what to do. We migrated most of the tables to InnoDB
(there was no reason to keep them as MyISAM, it was just legacy stuff). And
these problems were gone.

I don't know if this can be your case, but this is what happened to us.

Hope this helps.
Manuel.


Fwd: character set problem

2013-06-12 Thread Napster Cao


Begin forwarded message:

 From: Napster Cao tx...@hotmail.com
 Subject: character set problem
 Date: June 11, 2013 11:04:18 PM GMT+08:00
 To: mysql@lists.mysql.com
 
 Hi Guys,
 
 I installed a new CentOS server (6.4 x86_64), and when I try to log into 
 phpmyadmin, there's an ERROR:
 Can't initialize character set utf-8 (path: /usr/local/mysql/share/charsets/)
 
 BTW: Everytime I logged into system, I got:
 -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such 
 file or directory
 and I cannot find locale-gen on my system, the latest version of glibc is 
 installed.
 
 [admin@zxue /]# rpm -qa | grep glibc
 glibc-devel-2.12-1.107.el6.x86_64
 glibc-2.12-1.107.el6.x86_64
 glibc-headers-2.12-1.107.el6.x86_64
 glibc-common-2.12-1.107.el6.x86_64
 
 and here's the output of locale command:
 [admin@zxue /]# locale
 LANG=en_US
 LC_CTYPE=en_US.utf-8
 LC_NUMERIC=en_US.utf-8
 LC_TIME=en_US.utf-8
 LC_COLLATE=en_US.utf-8
 LC_MONETARY=en_US.utf-8
 LC_MESSAGES=en_US.utf-8
 LC_PAPER=en_US.utf-8
 LC_NAME=en_US.utf-8
 LC_ADDRESS=en_US.utf-8
 LC_TELEPHONE=en_US.utf-8
 LC_MEASUREMENT=en_US.utf-8
 LC_IDENTIFICATION=en_US.utf-8
 LC_ALL=en_US.utf-8
 
 How to resolve those two problems?(or maybe they are the same problem?)
 
 Thanks in advance!



Re: character set problem

2013-06-12 Thread Reindl Harald
independent how often you re-post it will not become magically
a MySQL problem if you have messed up your OS environment

Am 12.06.2013 15:27, schrieb Napster Cao:
 BTW: Everytime I logged into system, I got:
 -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such 
 file or directory
 and I cannot find locale-gen on my system, the latest version of glibc is 
 installed



signature.asc
Description: OpenPGP digital signature


RE: How do I select all rows of table that have some rows in another table (AND, not OR)

2013-06-12 Thread Rick James
Thinking out of the box... (And posting my reply at the 'wrong' end of the 
email.)...

Are there fewer than 64 genres?  Use a SET or BIGINT UNSIGNED.

AND sg.`genre_id` IN (10,38)
AND sg.`genre_id` NOT IN (22,61)

--
AND  genre  ((110) | (138)) != 0
AND  genre  ((122) | (161))  = 0

This would avoid having that extra table, and save a lot of space.

If you have more than 64 genres, then 
Plan A: clump them into some kind of application grouping and use multiple 
INTs/SETs.
Plan B: do mod  div arithmetic to compute which genre field to tackle.

For B, something like:
AND  (genre1  (10)) + (genre3  (18)) != 0
AND  (genre2  (12)) + (genre6  (11))  = 0
(That's assuming 10 bits per genre# field.  I would use 32 and INT UNSIGNED.)



 -Original Message-
 From: Daevid Vincent [mailto:dae...@daevid.com]
 Sent: Tuesday, June 11, 2013 4:17 PM
 To: mysql@lists.mysql.com
 Cc: 'shawn green'
 Subject: RE: How do I select all rows of table that have some rows in
 another table (AND, not OR)
 
 
 
  -Original Message-
  From: shawn green [mailto:shawn.l.gr...@oracle.com]
  Sent: Tuesday, June 11, 2013 2:16 PM
  To: mysql@lists.mysql.com
  Subject: Re: How do I select all rows of table that have some rows in
  another table (AND, not OR)
 
  Hello Daevid,
 
  On 6/11/2013 3:59 PM, Daevid Vincent wrote:
   I am trying to implement a filter so that a user could select
   various
  genres
   they want in or out. Perhaps they like 'action' and 'car chases'
   but don't like 'foreign' and 'drifting' (or whatever...)
  
   So I want something sort of like this, however IN() is using an OR
   comparison when I need it to be an AND
  
   SELECT DISTINCT
s.`scene_id` AS `id`,
GROUP_CONCAT(sg.`genre_id`) FROM
`dvds` AS d
JOIN `scenes_list` AS s
ON s.`dvd_id` = d.`dvd_id`
JOIN `scenes_genres` AS sg
ON sg.`scene_id` = s.`scene_id`
AND sg.`genre_id` IN (10,38)
AND sg.`genre_id` NOT IN (22,61) GROUP BY
   s.`scene_id`;
  
   This is giving me way way too many rows returned.
  
   For example, I would expect this scene_id to be in the result set:
  
   SELECT * FROM scenes_genres WHERE scene_id = 17;
  
   scene_id  genre_id
     --
  17   1
  17   3
  17  10 --
  17  19
  17  38 --
  17  53
  17  58
  17  59
  
   And this scene ID to NOT be in the result set:
  
   SELECT * FROM scenes_genres WHERE scene_id = 11;
  
   scene_id  genre_id
     --
  11   1
  11  10 --
  11  19
  11  31
  11  32
-- but does not have 38
  11  59
  
   I've tried various subselect ideas, but of course this fails b/c
 genre_id
   can't be multiple things at one time (AND)
  
   JOIN `scenes_genres` AS sg
 ON sg.`scene_id` = s.`scene_id`
AND sg.`genre_id` IN (
  SELECT `genre_id` FROM `scenes_genres`
   WHERE `genre_id` = 10
  AND `genre_id` = 38
  AND `genre_id`  22
  AND `genre_id`  61
   )
  
   And straight up like this failure too...
  
  JOIN `scenes_genres` AS sg
ON sg.`scene_id` = s.`scene_id`
   AND (sg.`genre_id` = 10 AND sg.`genre_id` = 38)
   AND NOT (sg.`genre_id` = 22 AND sg.`genre_id` = 61)
  
   So I'm sort of out of ideas at this point and hoping someone has a
   way
 to
  do
   this.
  
   Also, just for SG this is how we are currently implementing it, but
   we
  feel
   the REGEXP is killing our queries and while clever is a bit hacky
   and nullifies any indexes we have on the genres column as it
   requires a file_sort table scan to compare substrings basically...
  
   SELECT * FROM scene_all_genres WHERE scene_id = 17;
  
   scene_id  genres
     
  17  1|3|10|19|38|53|58|59|
  
   SELECT * FROM scene_all_genres WHERE scene_id = 11;
  
   scene_id  genres
     ---
  11  1|10|19|31|32|59|
  
   SELECT DISTINCT
s.`scene_id` AS `id`,
sg.`genres`
   FROM
`scene_all_genres` AS sg,
`dvds` AS d,
`scenes_list` AS s
   WHERE  dvd_id` = d.`dvd_id`
AND sg.`scene_id` = s.`scene_id`
AND sg.`genres` REGEXP '[[::]]10[[::]].*[[::]]38[[::]]'
AND sg.`genres` NOT REGEXP
  '(([[::]]22[[::]])|([[::]]61[[::]]))'
  
   ;
  
   http://dev.mysql.com/doc/refman/5.0/en/regexp.html#operator_regexp
  
   [[::]], [[::]]
  
   These markers stand for word boundaries. They match the beginning
   and
 end
  of
   words, respectively. A word is a sequence of word characters that 

Re: How do I select all rows of table that have some rows in another table (AND, not OR)

2013-06-12 Thread shawn green

Hello Daevid,

On 6/11/2013 7:17 PM, Daevid Vincent wrote:




-Original Message-
From: shawn green [mailto:shawn.l.gr...@oracle.com]
Sent: Tuesday, June 11, 2013 2:16 PM
To: mysql@lists.mysql.com
Subject: Re: How do I select all rows of table that have some rows in
another table (AND, not OR)

Hello Daevid,

... snip ...


Shawn, thank you for taking the time to reply. I wasn't expecting the
solution to be so much work with multiple statements like that. I was
thinking it could be done in one (or two, as in split out a portion of it in
PHP and re-insert it to the original SQL to avoid a JOIN or something). Part
of the issue is that we use PHP to generate the $sql string by appending
bits and pieces depending on the search criteria thereby keeping the 'path'
through the SQL statement simple and relatively linear. To implement this
would require significant re-writing and/or special cases where we could
introduce errors or omissions in the future. The frustrating part is that
the REGEXP query we use now only takes about 2 seconds on my DEV VM (same
database as PROD), however when the RDBMS is loaded it then takes up to 30
seconds so in theory it's not even that inefficient given the # rows. We do
use memcached for the results, but since there are so many combinations a
user could choose, our hit ratio is not so great and therefore the cache
isn't doing us much good and this is why the RDBMS can get loaded up easily.

How can an OR be so simple using IN() but AND be so overly complex?
Seems that mysql should have another function for ALL() that works just like
IN() to handle this kind of scenario.




As I said, we could have used a single command but you would have not 
been able to review the 'best' match scenario only those rows that were 
'complete' matches.


And, those three commands can easily be encapsulated within a stored 
procedure. Pass in two strings (one listing the values to find, one 
listing the values to reject) and use PREPARED STATEMENTS within the 
procedure to build the IN() lists within the first and second commands. 
 The value in the 'HAVING' clause in the last command (unless you use 
the other option of reviewing the list of 'closest' matches) can be set 
to the number of items in the list of things to find parameter to your 
procedure.


I was demonstrating a principle you could use and not necessarily giving 
you a full solution.  Some tweaking may be required.


Also,  by encapsulating what I wrote within a stored procedure, this 
changes my 3 statements to a single call that you can easily configure 
from your PHP application.


Regards,
--
Shawn Green
MySQL Principal Technical Support Engineer
Oracle USA, Inc. - Hardware and Software, Engineered to Work Together.
Office: Blountville, TN

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



RE: How do I select all rows of table that have some rows in another table (AND, not OR)

2013-06-12 Thread Daevid Vincent
This idea is so fancy pants and clever I *wish* it could have worked for me.
I checked and we actually have 65 genres currently (with more to come I'm
sure) LOL *FML*. I'm almost ashamed I didn't think of this. I 3 me some
bitmasks and this solution is so elegant. It's unfortunate there isn't a way
to use more than 64-bits natively.

You're RICK JAMES Bitch! :-p   (please tell me you know the Dave Chappelles
skit I'm referring to)

 -Original Message-
 From: Rick James [mailto:rja...@yahoo-inc.com]
 Sent: Wednesday, June 12, 2013 9:39 AM
 To: Daevid Vincent; mysql@lists.mysql.com
 Cc: 'shawn green'
 Subject: RE: How do I select all rows of table that have some rows in
 another table (AND, not OR)
 
 Thinking out of the box... (And posting my reply at the 'wrong' end of the
 email.)...
 
 Are there fewer than 64 genres?  Use a SET or BIGINT UNSIGNED.
 
 AND sg.`genre_id` IN (10,38)
 AND sg.`genre_id` NOT IN (22,61)
 
 --
 AND  genre  ((110) | (138)) != 0
 AND  genre  ((122) | (161))  = 0
 
 This would avoid having that extra table, and save a lot of space.
 
 If you have more than 64 genres, then
 Plan A: clump them into some kind of application grouping and use multiple
 INTs/SETs.
 Plan B: do mod  div arithmetic to compute which genre field to tackle.
 
 For B, something like:
 AND  (genre1  (10)) + (genre3  (18)) != 0
 AND  (genre2  (12)) + (genre6  (11))  = 0
 (That's assuming 10 bits per genre# field.  I would use 32 and INT
 UNSIGNED.)
 
 
 
  -Original Message-
  From: Daevid Vincent [mailto:dae...@daevid.com]
  Sent: Tuesday, June 11, 2013 4:17 PM
  To: mysql@lists.mysql.com
  Cc: 'shawn green'
  Subject: RE: How do I select all rows of table that have some rows in
  another table (AND, not OR)
 
 
 
   -Original Message-
   From: shawn green [mailto:shawn.l.gr...@oracle.com]
   Sent: Tuesday, June 11, 2013 2:16 PM
   To: mysql@lists.mysql.com
   Subject: Re: How do I select all rows of table that have some rows in
   another table (AND, not OR)
  
   Hello Daevid,
  
   On 6/11/2013 3:59 PM, Daevid Vincent wrote:
I am trying to implement a filter so that a user could select
various
   genres
they want in or out. Perhaps they like 'action' and 'car chases'
but don't like 'foreign' and 'drifting' (or whatever...)
   
So I want something sort of like this, however IN() is using an OR
comparison when I need it to be an AND
   
SELECT DISTINCT
 s.`scene_id` AS `id`,
 GROUP_CONCAT(sg.`genre_id`) FROM
 `dvds` AS d
 JOIN `scenes_list` AS s
 ON s.`dvd_id` = d.`dvd_id`
 JOIN `scenes_genres` AS sg
 ON sg.`scene_id` = s.`scene_id`
 AND sg.`genre_id` IN (10,38)
 AND sg.`genre_id` NOT IN (22,61) GROUP BY
s.`scene_id`;
   
This is giving me way way too many rows returned.
   
For example, I would expect this scene_id to be in the result set:
   
SELECT * FROM scenes_genres WHERE scene_id = 17;
   
scene_id  genre_id
  --
   17   1
   17   3
   17  10 --
   17  19
   17  38 --
   17  53
   17  58
   17  59
   
And this scene ID to NOT be in the result set:
   
SELECT * FROM scenes_genres WHERE scene_id = 11;
   
scene_id  genre_id
  --
   11   1
   11  10 --
   11  19
   11  31
   11  32
   -- but does not have 38
   11  59
   
I've tried various subselect ideas, but of course this fails b/c
  genre_id
can't be multiple things at one time (AND)
   
JOIN `scenes_genres` AS sg
  ON sg.`scene_id` = s.`scene_id`
 AND sg.`genre_id` IN (
   SELECT `genre_id` FROM `scenes_genres`
WHERE `genre_id` = 10
   AND `genre_id` = 38
   AND `genre_id`  22
   AND `genre_id`  61
)
   
And straight up like this failure too...
   
   JOIN `scenes_genres` AS sg
 ON sg.`scene_id` = s.`scene_id`
AND (sg.`genre_id` = 10 AND sg.`genre_id` = 38)
AND NOT (sg.`genre_id` = 22 AND sg.`genre_id` = 61)
   
So I'm sort of out of ideas at this point and hoping someone has a
way
  to
   do
this.
   
Also, just for SG this is how we are currently implementing it, but
we
   feel
the REGEXP is killing our queries and while clever is a bit hacky
and nullifies any indexes we have on the genres column as it
requires a file_sort table scan to compare substrings basically...
   
SELECT * FROM scene_all_genres WHERE scene_id = 17;
   
scene_id  genres
  

RE: How do I select all rows of table that have some rows in another table (AND, not OR)

2013-06-12 Thread Daevid Vincent
Oh! I must have misread. I didn't see how you had a solution for  64 bits.
I may have to experiment with that!

 -Original Message-
 From: Daevid Vincent [mailto:dae...@daevid.com]
 Sent: Wednesday, June 12, 2013 11:26 AM
 To: mysql@lists.mysql.com
 Subject: RE: How do I select all rows of table that have some rows in
 another table (AND, not OR)
 
 This idea is so fancy pants and clever I *wish* it could have worked for
 me. I checked and we actually have 65 genres currently (with more to come
 I'm sure) LOL *FML*. I'm almost ashamed I didn't think of this. I 3 me
 some bitmasks and this solution is so elegant. It's unfortunate there
 isn't a way to use more than 64-bits natively.
 
 You're RICK JAMES Bitch! :-p   (please tell me you know the Dave
 Chappelles skit I'm referring to)
 
  -Original Message-
  From: Rick James [mailto:rja...@yahoo-inc.com]
  Sent: Wednesday, June 12, 2013 9:39 AM
  To: Daevid Vincent; mysql@lists.mysql.com
  Cc: 'shawn green'
  Subject: RE: How do I select all rows of table that have some rows in
  another table (AND, not OR)
 
  Thinking out of the box... (And posting my reply at the 'wrong' end of
 the
  email.)...
 
  Are there fewer than 64 genres?  Use a SET or BIGINT UNSIGNED.
 
  AND sg.`genre_id` IN (10,38)
  AND sg.`genre_id` NOT IN (22,61)
 
  --
  AND  genre  ((110) | (138)) != 0
  AND  genre  ((122) | (161))  = 0
 
  This would avoid having that extra table, and save a lot of space.
 
  If you have more than 64 genres, then
  Plan A: clump them into some kind of application grouping and use
 multiple
  INTs/SETs.
  Plan B: do mod  div arithmetic to compute which genre field to tackle.
 
  For B, something like:
  AND  (genre1  (10)) + (genre3  (18)) != 0
  AND  (genre2  (12)) + (genre6  (11))  = 0
  (That's assuming 10 bits per genre# field.  I would use 32 and INT
  UNSIGNED.)
 
 
 
   -Original Message-
   From: Daevid Vincent [mailto:dae...@daevid.com]
   Sent: Tuesday, June 11, 2013 4:17 PM
   To: mysql@lists.mysql.com
   Cc: 'shawn green'
   Subject: RE: How do I select all rows of table that have some rows in
   another table (AND, not OR)
  
  
  
-Original Message-
From: shawn green [mailto:shawn.l.gr...@oracle.com]
Sent: Tuesday, June 11, 2013 2:16 PM
To: mysql@lists.mysql.com
Subject: Re: How do I select all rows of table that have some rows
 in
another table (AND, not OR)
   
Hello Daevid,
   
On 6/11/2013 3:59 PM, Daevid Vincent wrote:
 I am trying to implement a filter so that a user could select
 various
genres
 they want in or out. Perhaps they like 'action' and 'car
 chases'
 but don't like 'foreign' and 'drifting' (or whatever...)

 So I want something sort of like this, however IN() is using an
 OR
 comparison when I need it to be an AND

 SELECT DISTINCT
  s.`scene_id` AS `id`,
  GROUP_CONCAT(sg.`genre_id`) FROM
  `dvds` AS d
  JOIN `scenes_list` AS s
  ON s.`dvd_id` = d.`dvd_id`
  JOIN `scenes_genres` AS sg
  ON sg.`scene_id` = s.`scene_id`
  AND sg.`genre_id` IN (10,38)
  AND sg.`genre_id` NOT IN (22,61) GROUP BY
 s.`scene_id`;

 This is giving me way way too many rows returned.

 For example, I would expect this scene_id to be in the result set:

 SELECT * FROM scenes_genres WHERE scene_id = 17;

 scene_id  genre_id
   --
17   1
17   3
17  10 --
17  19
17  38 --
17  53
17  58
17  59

 And this scene ID to NOT be in the result set:

 SELECT * FROM scenes_genres WHERE scene_id = 11;

 scene_id  genre_id
   --
11   1
11  10 --
11  19
11  31
11  32
  -- but does not have 38
11  59

 I've tried various subselect ideas, but of course this fails b/c
   genre_id
 can't be multiple things at one time (AND)

 JOIN `scenes_genres` AS sg
   ON sg.`scene_id` = s.`scene_id`
  AND sg.`genre_id` IN (
SELECT `genre_id` FROM `scenes_genres`
 WHERE `genre_id` = 10
AND `genre_id` = 38
AND `genre_id`  22
AND `genre_id`  61
 )

 And straight up like this failure too...

JOIN `scenes_genres` AS sg
  ON sg.`scene_id` = s.`scene_id`
 AND (sg.`genre_id` = 10 AND sg.`genre_id` = 38)
 AND NOT (sg.`genre_id` = 22 AND sg.`genre_id` = 61)

 So I'm sort of out of 

RE: How do I select all rows of table that have some rows in another table (AND, not OR)

2013-06-12 Thread Rick James
I'm the ORIGINAL Rick James, B  (And, I'm still alive.)  LOL

If you are using PHP, you might want to stop at 31 bits per INT/SET.  PHP seems 
not to yet be in the 64-bit world.

 -Original Message-
 From: Daevid Vincent [mailto:dae...@daevid.com]
 Sent: Wednesday, June 12, 2013 11:26 AM
 To: mysql@lists.mysql.com
 Subject: RE: How do I select all rows of table that have some rows in
 another table (AND, not OR)
 
 This idea is so fancy pants and clever I *wish* it could have worked for
 me.
 I checked and we actually have 65 genres currently (with more to come I'm
 sure) LOL *FML*. I'm almost ashamed I didn't think of this. I 3 me some
 bitmasks and this solution is so elegant. It's unfortunate there isn't a
 way to use more than 64-bits natively.
 
 You're RICK JAMES Bitch! :-p   (please tell me you know the Dave
 Chappelles
 skit I'm referring to)
 
  -Original Message-
  From: Rick James [mailto:rja...@yahoo-inc.com]
  Sent: Wednesday, June 12, 2013 9:39 AM
  To: Daevid Vincent; mysql@lists.mysql.com
  Cc: 'shawn green'
  Subject: RE: How do I select all rows of table that have some rows in
  another table (AND, not OR)
 
  Thinking out of the box... (And posting my reply at the 'wrong' end of
  the email.)...
 
  Are there fewer than 64 genres?  Use a SET or BIGINT UNSIGNED.
 
  AND sg.`genre_id` IN (10,38)
  AND sg.`genre_id` NOT IN (22,61)
 
  --
  AND  genre  ((110) | (138)) != 0
  AND  genre  ((122) | (161))  = 0
 
  This would avoid having that extra table, and save a lot of space.
 
  If you have more than 64 genres, then
  Plan A: clump them into some kind of application grouping and use
  multiple INTs/SETs.
  Plan B: do mod  div arithmetic to compute which genre field to tackle.
 
  For B, something like:
  AND  (genre1  (10)) + (genre3  (18)) != 0
  AND  (genre2  (12)) + (genre6  (11))  = 0 (That's assuming
  10 bits per genre# field.  I would use 32 and INT
  UNSIGNED.)
 
 
 
   -Original Message-
   From: Daevid Vincent [mailto:dae...@daevid.com]
   Sent: Tuesday, June 11, 2013 4:17 PM
   To: mysql@lists.mysql.com
   Cc: 'shawn green'
   Subject: RE: How do I select all rows of table that have some rows
   in another table (AND, not OR)
  
  
  
-Original Message-
From: shawn green [mailto:shawn.l.gr...@oracle.com]
Sent: Tuesday, June 11, 2013 2:16 PM
To: mysql@lists.mysql.com
Subject: Re: How do I select all rows of table that have some rows
in another table (AND, not OR)
   
Hello Daevid,
   
On 6/11/2013 3:59 PM, Daevid Vincent wrote:
 I am trying to implement a filter so that a user could select
 various
genres
 they want in or out. Perhaps they like 'action' and 'car
 chases'
 but don't like 'foreign' and 'drifting' (or whatever...)

 So I want something sort of like this, however IN() is using an
 OR
 comparison when I need it to be an AND

 SELECT DISTINCT
  s.`scene_id` AS `id`,
  GROUP_CONCAT(sg.`genre_id`) FROM
  `dvds` AS d
  JOIN `scenes_list` AS s
  ON s.`dvd_id` = d.`dvd_id`
  JOIN `scenes_genres` AS sg
  ON sg.`scene_id` = s.`scene_id`
  AND sg.`genre_id` IN (10,38)
  AND sg.`genre_id` NOT IN (22,61) GROUP BY
 s.`scene_id`;

 This is giving me way way too many rows returned.

 For example, I would expect this scene_id to be in the result set:

 SELECT * FROM scenes_genres WHERE scene_id = 17;

 scene_id  genre_id
   --
17   1
17   3
17  10 --
17  19
17  38 --
17  53
17  58
17  59

 And this scene ID to NOT be in the result set:

 SELECT * FROM scenes_genres WHERE scene_id = 11;

 scene_id  genre_id
   --
11   1
11  10 --
11  19
11  31
11  32
  -- but does not have 38
11  59

 I've tried various subselect ideas, but of course this fails b/c
   genre_id
 can't be multiple things at one time (AND)

 JOIN `scenes_genres` AS sg
   ON sg.`scene_id` = s.`scene_id`
  AND sg.`genre_id` IN (
SELECT `genre_id` FROM `scenes_genres`
 WHERE `genre_id` = 10
AND `genre_id` = 38
AND `genre_id`  22
AND `genre_id`  61
 )

 And straight up like this failure too...

JOIN `scenes_genres` AS sg
  ON sg.`scene_id` = s.`scene_id`
 AND (sg.`genre_id` = 10 AND sg.`genre_id` = 38)
 AND NOT 

RE: How do I select all rows of table that have some rows in another table (AND, not OR)

2013-06-12 Thread Paul Halliday
I am so, so glad that someone finally said what I think each time I see a 
message from you Mr. James. 

 Original message 
From: Rick James rja...@yahoo-inc.com 
Date: 06-12-2013  8:45 PM  (GMT-04:00) 
To: Daevid Vincent dae...@daevid.com,mysql@lists.mysql.com 
Subject: RE: How do I select all rows of table that have some rows in
  another table (AND, not OR) 
 
I'm the ORIGINAL Rick James, B  (And, I'm still alive.)  LOL

If you are using PHP, you might want to stop at 31 bits per INT/SET.  PHP seems 
not to yet be in the 64-bit world.

 -Original Message-
 From: Daevid Vincent [mailto:dae...@daevid.com]
 Sent: Wednesday, June 12, 2013 11:26 AM
 To: mysql@lists.mysql.com
 Subject: RE: How do I select all rows of table that have some rows in
 another table (AND, not OR)
 
 This idea is so fancy pants and clever I *wish* it could have worked for
 me.
 I checked and we actually have 65 genres currently (with more to come I'm
 sure) LOL *FML*. I'm almost ashamed I didn't think of this. I 3 me some
 bitmasks and this solution is so elegant. It's unfortunate there isn't a
 way to use more than 64-bits natively.
 
 You're RICK JAMES Bitch! :-p   (please tell me you know the Dave
 Chappelles
 skit I'm referring to)
 
  -Original Message-
  From: Rick James [mailto:rja...@yahoo-inc.com]
  Sent: Wednesday, June 12, 2013 9:39 AM
  To: Daevid Vincent; mysql@lists.mysql.com
  Cc: 'shawn green'
  Subject: RE: How do I select all rows of table that have some rows in
  another table (AND, not OR)
 
  Thinking out of the box... (And posting my reply at the 'wrong' end of
  the email.)...
 
  Are there fewer than 64 genres?  Use a SET or BIGINT UNSIGNED.
 
  AND sg.`genre_id` IN (10,38)
  AND sg.`genre_id` NOT IN (22,61)
 
  --
  AND  genre  ((110) | (138)) != 0
  AND  genre  ((122) | (161))  = 0
 
  This would avoid having that extra table, and save a lot of space.
 
  If you have more than 64 genres, then
  Plan A: clump them into some kind of application grouping and use
  multiple INTs/SETs.
  Plan B: do mod  div arithmetic to compute which genre field to tackle.
 
  For B, something like:
  AND  (genre1  (10)) + (genre3  (18)) != 0
  AND  (genre2  (12)) + (genre6  (11))  = 0 (That's assuming
  10 bits per genre# field.  I would use 32 and INT
  UNSIGNED.)
 
 
 
   -Original Message-
   From: Daevid Vincent [mailto:dae...@daevid.com]
   Sent: Tuesday, June 11, 2013 4:17 PM
   To: mysql@lists.mysql.com
   Cc: 'shawn green'
   Subject: RE: How do I select all rows of table that have some rows
   in another table (AND, not OR)
  
  
  
-Original Message-
From: shawn green [mailto:shawn.l.gr...@oracle.com]
Sent: Tuesday, June 11, 2013 2:16 PM
To: mysql@lists.mysql.com
Subject: Re: How do I select all rows of table that have some rows
in another table (AND, not OR)
   
Hello Daevid,
   
On 6/11/2013 3:59 PM, Daevid Vincent wrote:
 I am trying to implement a filter so that a user could select
 various
genres
 they want in or out. Perhaps they like 'action' and 'car
 chases'
 but don't like 'foreign' and 'drifting' (or whatever...)

 So I want something sort of like this, however IN() is using an
 OR
 comparison when I need it to be an AND

 SELECT DISTINCT
  s.`scene_id` AS `id`,
  GROUP_CONCAT(sg.`genre_id`) FROM
  `dvds` AS d
  JOIN `scenes_list` AS s
  ON s.`dvd_id` = d.`dvd_id`
  JOIN `scenes_genres` AS sg
  ON sg.`scene_id` = s.`scene_id`
  AND sg.`genre_id` IN (10,38)
  AND sg.`genre_id` NOT IN (22,61) GROUP BY
 s.`scene_id`;

 This is giving me way way too many rows returned.

 For example, I would expect this scene_id to be in the result set:

 SELECT * FROM scenes_genres WHERE scene_id = 17;

 scene_id  genre_id
   --
    17   1
    17   3
    17  10 --
    17  19
    17  38 --
    17  53
    17  58
    17  59

 And this scene ID to NOT be in the result set:

 SELECT * FROM scenes_genres WHERE scene_id = 11;

 scene_id  genre_id
   --
    11   1
    11  10 --
    11  19
    11  31
    11  32
    -- but does not have 38
    11  59

 I've tried various subselect ideas, but of course this fails b/c
   genre_id
 can't be multiple things at one time (AND)

 JOIN `scenes_genres` AS sg
   ON sg.`scene_id` = s.`scene_id`
  AND sg.`genre_id` IN (
    SELECT `genre_id` FROM `scenes_genres`
 WHERE `genre_id` = 10