MySQL 5.5 to 5.7 stopped using indexes - php

I have a Magento 1.9.2.1 . And it successfully running on Apache2 and MySQL 5.5.
I have tried to migrate it to another server and used NGINX and MySQL 5.7 for it.
But website started to be very slow (12 seconds against 2).
After several hours of debug I have found that there is a problem in one query:
SELECT
`main_table`.`entity_id`,
`main_table`.`name`,
`main_table`.`path`,
`main_table`.`is_active`,
`main_table`.`is_anchor`,
`url_rewrite`.`request_path`
FROM
`catalog_category_flat_store_1` AS `main_table`
LEFT JOIN
`core_url_rewrite` AS `url_rewrite` ON
`url_rewrite`.`category_id` = `main_table`.`entity_id` AND
`url_rewrite`.`is_system` = 1 AND
`url_rewrite`.`store_id` = 1 AND
`url_rewrite`.`id_path` LIKE 'category/%'
WHERE
(`main_table`.`include_in_menu` = '1') AND
(`main_table`.`is_active` = '1') AND
(`main_table`.`path` like '1/2/%')
ORDER BY
`main_table`.`position` ASC;
And on explain I have found that there is no index used. On the old MySQL 5.5 server explain command showing index in use. Once I force usage of index - new server answers in 0.01s instead of 10s. But I think that it is not good idea to change sourcefiles of magento code.
Is there a way to force MySQL 5.7 work in similar way as 5.5 in index choosing?.

Sadly only MySQL downgrade from 5.7 to 5.5 fixed similar issue for me.
Magento sql query have no index

Just for anyone else searching this like I was today, there's a simple fix you can apply to app/code/core/Mage/Catalog/Helper/Category/Url/rewrite.php
details here - https://github.com/hvanmegen/magento-mysql-5.7-join-fix

Related

How to query a JSON column using the -> operator in mariadb

I'm trying to get schedules comparing the json column data with following code in a Laravel project:
$schedules = Schedule::where('schedule_with->company_person', $contact_company_person->id)->get();
This generates SQL query like below:
select * from `schedules` where `schedule_with`->'$."company_person"' = 1;
While this works for MYSQL 5.7 and above but not working for MARIADB 10.5. But MARIADB already supports JSON column from 10.2 onward.
For MARIADB, following query works:
select * from schedules where JSON_Value(schedule_with, "$.company_person") = 3;
Is there some config changes required in Laravel to make it work?
I know it can be achieved with raw query, I'm curious about what am I missing?
Thank you,
No, there is no configuration change you can do to enable this.
To quote MariaDB's documentation on differences between 10.5 and MySQL (8):
MariaDB 10.5 does not support MySQL's JSON operators (-> and ->>).
"No ifs, no buts".
I guess you could do it with a regular expression replacement that edits the SQL that Laravel generates just before the SQL is executed, but that is both rather hard to execute and it seems too hacky to be worth it. A raw where query, by comparison, is not that unsightly:
$table->whereRaw('JSON_VALUE(schedule_with, ?) = ?', ['$.company_person', 3])

Receiving MySQL Error in PHPMyAdmin

BACKGROUND: I am using PHPMyAdmin tool to run MySQL queries. MySQL version is 5.1.55. I have been using MySQL and this PHPMyAdmin tool for about 7 years and have never seen this error. I am trying to do a simple update query changing ne to gb (column = team, table = info). When I use PHPMyAdmin to try to make the changes,
I get the error message:
UPDATE `pickem`.`info` SET `team` = 'gb' WHERE CONVERT(`info`.`team` USING utf8) = \'ne\'.
QUESTION: What is going wrong here? What is the CONVERT Using UTF8 message coming from. How can I get this to just update the fields I want? I have tried to type the SQL code in myself ex: update info set team ="gb" where team = "ne" , but that does not work either. I get the error message:
There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem
ERROR: Unknown Punctuation String # 22
STR: =\
SQL: update info set team =\"gb\" where team = \"ne\"
It seems the system is putting the slashes in there and it is not letting me do this simple update query.
I appreciate any advice on how to fix this.
Thanks!
You are using phpMyAdmin, right? Try using HeidiSQL.
Also check your PHP version, gpc_magic_quotes is already removed at PHP 5.4.0
I tried running your code on phpMyAdmin, removed the backslashes at \'ne\' and its running fine.
Try running a simple update query in HeidiSQL and check if the problem exists.
UPDATE `pickem`.`info` SET `team` = 'gb'
If it runs fine, modify it like
UPDATE `pickem`.`info` SET `team` = 'gb' WHERE `team` = 'ne'
Additional sidenote - check the encoding and data types. You might have overlooked something...
If your query runs fine on HeidiSQL, you can safely assume that something is wrong with your phpMyAdmin installation/configuration
EDIT:
Are the values you are providing contain '\' inside them? If so, you have to do it like
UPDATE `pickem`.`info` SET `team` = 'gb\\'
EDIT 2:
For the meantime, try to use this to solve your problem temporarily.
UPDATE `pickem`.`info` SET `team` = CONCAT('en') WHERE `team` = CONCAT('gb')
EDIT 3:
If all else fails, you probably should get this or this. Since you are on PHP 5.3, I am afraid to say that the gpc_magic_quotes option might have been enabled by your hosting provider. Contact them.

Why isn't MySQL allowing access to columns with dot notation?

According to the [PHP manual item on MySQL Field tables], I should be able to use the following syntax to access table columns with PHP 5.3 and MySQL:
$query = "SELECT account.*, country.* FROM account,
country WHERE country.name = 'Portugal' AND account.country_id = country.id";
This syntax works on the live site on which I'm trying to work locally.
However, running the same version of PHP with the syntax above on my machine throws a syntax error on the star:
You have an error in your SQL syntax;
check the manual that corresponds to your
MySQL server version for the right syntax to use near '*' at line 1
EDIT:
Here is the version of mySql this isn't working on:
Server version: 5.1.43-community
Protocol version: 10
Using PHP 5.3.0 on Apache 2/2.11
I appreciate the help on this. I can't know exactly what my problem was but a few things I changed:
1. The original server was using fastcgi while I was using apache, this i changed
2. The original server was running non-thread safe PHP but I was, this I changed by installing a module on wamp as well as a NTS version of the same php
I wont leave as answer bc I dont know what it is
It looks like you're trying to retrieve all of the columns from account and country. If that's correct, you can use the following (I'm also going to use the JOIN as #Juan mentioned in his comment):
$query = "SELECT * FROM account JOIN country ON account.country_id = country.id WHERE country.name = 'Portugal'";
Because you joined the tables you can't use the '*' wildcard to grab all the columns from each table individually. This is why MySQL threw an error.
To get the all the columns from the results of your join you can use:
$query = "SELECT * FROM account,country WHERE country.name = 'Portugal' AND account.country_id = country.id";

mysql_query Update of varchar doesn´t work with "-"

I'm trying to find out what the problem is since hours. I have a varchar(255).
works:
mysql_query("UPDATE `servers` SET `url`='quicktest' WHERE `id`=63");
doesn't work:
mysql_query("UPDATE `servers` SET `url`='quick-test' WHERE `id`=63");
What is wrong with the "-" chars that it doesn't work? I mean I can update it in phpmyadmin without problems and sometimes it even works via mysql_query. (1 of 20 cases)
About mysql_query I know that it is outdated but it is just updating internal stuff.
Update #1
I did not had this problem on an old debian 6 server but since it is on ubuntu 13.10 with maria db and php5-fpm I can´t use this script any more and I don´t get any errors.
Update #2
As it looks like it was related to either caching via the apache modules or the google pagespeed module.
Not a solution, but maybe it's worth to try:
$temp_url = mysql_real_escape_string('quick-test');
mysql_query("UPDATE `servers` SET `url`='".$temp_url."' WHERE `id`=63");

query with non Latin characters gives error or stuck mysql 5.6

Our DB was upgraded from mysql 5.5 to mysql 5.6, properties are the same (encoding and such, that is what I am told)
A query with non latin characters that worked fine on mysql 5.5 now fails and issues a 1064Error
Or the phpMyadmin gets stuck loading...
SELECT *
FROM search_1
WHERE pair_type="pair_one"
AND ( symbol LIKE 'Евро%' OR (pair_name_trans) LIKE ('Евро%'))
ORDER BY orders DESC
LIMIT 15;
Searching for just the symbol LIKE 'Евро%' also works fine.
Any ideas?
(already tried to SET NAMES) tnx.

Categories