mysql-5.7

Poor whereHas performance in Laravel

假如想象 提交于 2019-12-02 19:35:21
I want to apply a where condition to relation. Here's what I do: Replay::whereHas('players', function ($query) { $query->where('battletag_name', 'test'); })->limit(100); It generates the following query: select * from `replays` where exists ( select * from `players` where `replays`.`id` = `players`.`replay_id` and `battletag_name` = 'test') order by `id` asc limit 100; Which executes in 70 seconds. If I manually rewrite query like this: select * from `replays` where id in ( select replay_id from `players` where `battletag_name` = 'test') order by `id` asc limit 100; It executes in 0.4 seconds.

Where is MySQL 5.7 my.cnf file?

爱⌒轻易说出口 提交于 2019-12-02 17:42:40
In Ubuntu I had my.cnf file of MySQL 5.6 in /etc/my.cnf . But I can't find the same file of MySQL 5.7. From where can I find that? I did a find in entire / (root). But I couldn't find it anywhere. Any clues? I'm trying to set max_connections value. In MySQL 5.7, the default cnf is at: /etc/mysql/mysql.conf.d/mysqld.cnf mysql --help printed below. Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf The following groups are read: mysql client The following options may be given as the first argument: --print-defaults Print the program

How to create a JSON object in MySql with a boolean value?

…衆ロ難τιáo~ 提交于 2019-12-02 17:00:39
问题 I would like my MySql query to return a JSON object that looks as follows: {"name": "Piotr", "likesMysql": true} This seems to be working fine when I do: SELECT json_object( 'name', 'Piotr', 'likesMysql', TRUE ) However when I try to derive the likesMysql from an if expression I get 0 and 1 instead of false and true e.g.: SELECT json_object( 'name', 'Piotr', 'likesMysql', if(4 MOD 2 = 0, TRUE, FALSE) ) results in {"name": "Piotr", "likesMysql": 1} How do I use the json_object to construct a

MySQL 5.7 STR_TO_DATE

。_饼干妹妹 提交于 2019-12-02 12:03:12
I am running MySQL 5.7 and wanted to convert some strings to date. I referred the manual here: http://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_str-to-date And tried out the following(please note the MySQL version) mysql> SELECT STR_TO_DATE('9','%m'); +-----------------------+ | STR_TO_DATE('9','%m') | +-----------------------+ | NULL | +-----------------------+ 1 row in set, 1 warning (0.00 sec) mysql> show warnings; +---------+------+--------------------------------------------------------+ | Level | Code | Message | +---------+------+-----------------------------

How to create a JSON object in MySql with a boolean value?

不打扰是莪最后的温柔 提交于 2019-12-02 09:18:18
I would like my MySql query to return a JSON object that looks as follows: {"name": "Piotr", "likesMysql": true} This seems to be working fine when I do: SELECT json_object( 'name', 'Piotr', 'likesMysql', TRUE ) However when I try to derive the likesMysql from an if expression I get 0 and 1 instead of false and true e.g.: SELECT json_object( 'name', 'Piotr', 'likesMysql', if(4 MOD 2 = 0, TRUE, FALSE) ) results in {"name": "Piotr", "likesMysql": 1} How do I use the json_object to construct a JSON object that has true or false as property value? This seems to be a bug in MySql . You can

Which collation to use so that `ş` and `s` are treated as unique values?

ⅰ亾dé卋堺 提交于 2019-12-02 08:20:54
The issue is that ş and s are interpreted by MySQL as identical values. I'm new to MySQL, so I have no idea which collations would view them as unique. The collations that I've tried using which don't work are: utf8_general_ci utf8_unicode_520_ci utf8mb4_unicode_ci utf8mb4_unicode_520_ci Does anybody know which collation to use? P.S. I also really need the collation to interpret emojis and other non-Latin characters, and, to my knowledge of MySQL and collations, the only collation able to do this is unicode ? utf8_turkish_ci and utf8_romanian_ci -- as shown in http://mysql.rjweb.org/utf8

MySQL, Select records based on values in JSON array

∥☆過路亽.° 提交于 2019-12-02 01:19:43
I'm still pretty new to handling JSON fields in MySQL. All the solutions I've come across deal with objects that have key/values; unable to find one that handles JSON arrays. Anyways, what I want to do is to be able to select all rows where the interestIds contain 2 in them. How do I do that? Thanks. Users table +----+-------------+ | id | interestIds | +----+-------------+ | 1 | [1, 2] | | 2 | [3, 2] | | 3 | [2, 4] | +----+-------------+ Sample test query: SET @userId = 2; SELECT * FROM Users WHERE @userId IN JSON_CONTAINS(@user, interestIds, '$[1]'); I am confused as how to use the JSON_*

mysql, space equals empty string

断了今生、忘了曾经 提交于 2019-12-01 16:32:56
Just took me 2 hours to troubleshoot an issue on my backend. Cause was that of empty string being equal to space: SELECT ' ' = ''; -> 1 SELECT STRCMP(' ', ''); -> 0 /* means equal */ Interestingly enough, SELECT '' REGEXP '[ ]'; -> 0 SELECT '' REGEXP ' '; -> 0 SELECT ' ' REGEXP ' '; -> 1 Can I prevent this? Is it a setting? The reason this fails is explained in the docs here http://dev.mysql.com/doc/refman/5.0/en/char.html : Values in CHAR and VARCHAR columns are sorted and compared according to the character set collation assigned to the column. All MySQL collations are of type PADSPACE. This

MySQL: Invalid GIS data provided to function st_geometryfromtext

余生颓废 提交于 2019-12-01 09:41:43
Here's my code: SET @poly = 'Polygon((-98.07697478272888 30.123832577126326, -98.07697478272888 30.535734310413392, -97.48302581787107 30.535734310413392, -97.48302581787107 30.123832577126326))'; SELECT name FROM county_shapes WHERE MBRContains(ST_GeomFromText(@poly), SHAPE); Whenever I run that I get a "MySQL: Invalid GIS data provided to function st_geometryfromtext" error. This returns the same error: SELECT name FROM county_shapes WHERE MBRContains(ST_GeomFromText('Polygon((-98.07697478272888 30.123832577126326, -98.07697478272888 30.535734310413392, -97.48302581787107 30.535734310413392,

Mysql 5.7 native json support - control keys order in json_insert function

谁说我不能喝 提交于 2019-12-01 05:12:14
I am facing issues with json key ordering while inserting using json_insert function. I have the sorted records as below "AIR", "AIR Express" "CFR", "Cost and Freight" "FH", "Free house" "UN", "United Nations" "UPS", "United Parcel Service" After converting the above records into json using json_insert function, I am seeing the results as below {"FH":"Free house", "UN": "United Nations", "AIR": "AIR Express", "CFR": "Cost and Freight", "UPS": "United Parcel Service"} but I want the json to maintain the keys in the order I am inserting. Though I could sense that it is trying to maintain the