Forum Moderators: coopster
1. Is there a MySQL query length in terms of number of characters?
2. Is there a maximum number of matching criteria after the where clause, ie. x=1 or x=2 ... x=1024 ... x=59623?
I have a list of keys (1000+) where I want to match them to a table. Should I do the search in 1 query as in 2. Or should I do them one by one = 1000+ queries?
select * from something where x in (1,2,3,4.....)
or if they are successive you could do
select * from something where x between 1 and 1000
select * from something where x < 1000
select * from something where x > 3 and x < 1003
MySQL Comparison Operators [mysql.com]
Not in terms of characters, but bytes. It is controlled by the max_allowed_packet [mysql.com] system variable. You can use SHOW VARIABLES to see your server settings, for example:
SHOW VARIABLES LIKE 'max_allowed_packet';
+--------------------+---------+
¦ Variable_name......¦ Value...¦
+--------------------+---------+
¦ max_allowed_packet ¦ 1047552 ¦
+--------------------+---------+
The maximum size of one packet. The message buffer is initialized tomax_allowed_packet, but can grow up tonet_buffer_length bytesbytes when needed. This value by default is small, to catch big (possibly wrong) packets. You must increase this value if you are using bigmax_allowed_packetcolumns. It should be as big as the biggestBLOByou want to use. The protocol limits forBLOBis 16M in MySQL 3.23 and 1G in MySQL 4.0.max_allowed_packet
You'll get a Packet too large Error [mysql.com] if the
mysqld server gets a packet bigger than max_allowed_packet bytes.