importing table with primary auto_increment value zero to mariadb - mysql

I'm trying to import database dump into my mariaDb 10.2.6 database.
It's a Magento 2 database.
There is this table import:
# Dump of table store_website
# ------------------------------------------------------------
DROP TABLE IF EXISTS `store_website`;
CREATE TABLE `store_website` (
`website_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Website Id',
`code` varchar(32) DEFAULT NULL COMMENT 'Code',
`name` varchar(64) DEFAULT NULL COMMENT 'Website Name',
`sort_order` smallint(5) unsigned NOT NULL DEFAULT 0 COMMENT 'Sort Order',
`default_group_id` smallint(5) unsigned NOT NULL DEFAULT 0 COMMENT 'Default Group Id',
`is_default` smallint(5) unsigned DEFAULT 0 COMMENT 'Defines Is Website Default',
PRIMARY KEY (`website_id`),
UNIQUE KEY `STORE_WEBSITE_CODE` (`code`),
KEY `STORE_WEBSITE_SORT_ORDER` (`sort_order`),
KEY `STORE_WEBSITE_DEFAULT_GROUP_ID` (`default_group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Websites';
LOCK TABLES `store_website` WRITE;
/*!40000 ALTER TABLE `store_website` DISABLE KEYS */;
INSERT INTO `store_website` (`website_id`, `code`, `name`, `sort_order`, `default_group_id`, `is_default`)
VALUES
(0,'admin','Admin',0,0,0),
(1,'my_website','MY_WEBSITE',0,1,1);
/*!40000 ALTER TABLE `store_website` ENABLE KEYS */;
UNLOCK TABLES;
This fails giving me a duplicate key 1 error. Obviously it tries to insert the value 0 as a new increment which would be 1 but that is already in the table.
This error appears even though these options are set:
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET #OLD_SQL_NOTES=##SQL_NOTES, SQL_NOTES=0 */;

As far as I know the InnoDB engine does not support the NO_AUTO_VALUE_ON_ZERO mode. It should be supported by MyISAM though.
Note that using zero as a key in a auto_increment column is not a recommended practice, so it is advisable to avoid it. Is it an option to import the data to MyISAM-tables, do whatever to change the zero-keys to positive numbers and then switch to InnoDB?

Related

MySQL why AUTO_INCREMENT does not start at 0 when using CREATE TABLE in MySQL Workbench (8.0)

Using MySQL Workbench 8.0, I'm using table table create statements based on an existing (database) table containers.
DROP TABLE IF EXISTS `containers`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `containers` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`customer_id` int(10) NOT NULL,
`waste_id` int(10) DEFAULT NULL,
[.. etc etc ..]
`created_at` datetime NOT NULL,
`updated_at` datetime DEFAULT NULL,
`removed` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4293 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = #saved_cs_client */;
/*!40103 SET TIME_ZONE=#OLD_TIME_ZONE */;
Why is this statement generating an ENGINE=InnoDB AUTO_INCREMENT=4293 that starts at value 4293?
Since it is a table CREATE statement, is it always expecting that one copies existing records in the old table to the newly created tables? And continues working with the newly created table?
I would expect it to start at the value 0 when creating an new table.
Any idea what I'm missing? Thanks!

#1005 - Errcode: 150 "Foreign key constraint is incorrectly formed" Implementing database

I am trying to implement a database made in MySQL Workbench into PHPMyadmin. However, I tried a lot and it is not working. It is telling me that a certain table can't be made, since the foreign key constraint is incorrectly formed. Hopefully any of you see what is wrong with my code.
Here is my code:
-- MySQL dump 10.13 Distrib 8.0.16, for Win64 (x86_64)
--
-- Host: localhost Database: db-website
-- ------------------------------------------------------
-- Server version 8.0.15
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
SET NAMES utf8 ;
/*!40103 SET #OLD_TIME_ZONE=##TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET #OLD_SQL_NOTES=##SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `tblcategory`
--
DROP TABLE IF EXISTS `tblcategory`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
SET character_set_client = utf8 ;
CREATE TABLE `tblcategory` (
`ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`strName` varchar(45) NOT NULL,
`strDescription` varchar(100) NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `ID_UNIQUE` (`ID`),
UNIQUE KEY `strName_UNIQUE` (`strName`),
UNIQUE KEY `strDescription_UNIQUE` (`strDescription`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `tblcategory`
--
LOCK TABLES `tblcategory` WRITE;
/*!40000 ALTER TABLE `tblcategory` DISABLE KEYS */;
INSERT INTO `tblcategory` VALUES (1,'Beers','Beers - description...'),(2,'Wines','Wines - description...'),(3,'Liquors','Liquors - description...');
/*!40000 ALTER TABLE `tblcategory` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `tblproduct`
--
DROP TABLE IF EXISTS `tblproduct`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
SET character_set_client = utf8 ;
CREATE TABLE `tblproduct` (
`ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`strName` varchar(45) NOT NULL,
`decPrice` decimal(10,2) unsigned NOT NULL,
`intVolume` decimal(10,2) unsigned NOT NULL,
`strDescription` varchar(100) NOT NULL,
`idProductCategory` int(10) unsigned NOT NULL,
`idProductSubCategory` int(10) unsigned NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `ID_UNIQUE` (`ID`),
UNIQUE KEY `strName_UNIQUE` (`strName`),
UNIQUE KEY `strDescription_UNIQUE` (`strDescription`),
KEY `ProductSubCategory_idx` (`idProductSubCategory`),
KEY `ProductCategory_idx` (`idProductCategory`),
CONSTRAINT `ProductCategory` FOREIGN KEY (`idProductCategory`) REFERENCES `tblcategory` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `ProductSubCategory` FOREIGN KEY (`idProductSubCategory`) REFERENCES `tblsubcategory` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `tblproduct`
--
LOCK TABLES `tblproduct` WRITE;
/*!40000 ALTER TABLE `tblproduct` DISABLE KEYS */;
INSERT INTO `tblproduct` VALUES (1,'Heineken H41',6.99,2.00,'Heineken H41 Lager',1,2),(2,'G7 sauvignon blanc',5.00,0.75,'G7 sauvignon blanc White Wine ',2,12),(3,'Jack Daniel\'s Tennessee',26.99,0.70,'Jack Daniel\'s Tennessee Whiskey',3,21);
/*!40000 ALTER TABLE `tblproduct` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `tblsubcategory`
--
DROP TABLE IF EXISTS `tblsubcategory`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
SET character_set_client = utf8 ;
CREATE TABLE `tblsubcategory` (
`ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`strName` varchar(45) NOT NULL,
`strDescription` varchar(45) NOT NULL,
`idCategory` int(10) unsigned NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `ID_UNIQUE` (`ID`),
UNIQUE KEY `strName_UNIQUE` (`strName`),
KEY `SubCategory-Category_idx` (`idCategory`),
CONSTRAINT `SubCategory-Category` FOREIGN KEY (`idCategory`) REFERENCES `tblcategory` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `tblsubcategory`
--
LOCK TABLES `tblsubcategory` WRITE;
/*!40000 ALTER TABLE `tblsubcategory` DISABLE KEYS */;
INSERT INTO `tblsubcategory` VALUES (1,'Ale','Description...',1),(2,'Lager','Description...',1),(3,'Pilsner','Description...',1),(4,'Stout','Description...',1),(5,'Porter','Description...',1),(6,'Bock','Description...',1),(7,'Weissbier','Description...',1),(8,'Lambic','Description...',1),(9,'Kölsch','Description...',1),(10,'Malt Liquor','Description...',1),(11,'Red Wine','Description...',2),(12,'White Wine','Description...',2),(13,'Rosé Wine','Description...',2),(14,'Sparkling Wine','Description...',2),(15,'Fortified Wine','Description...',2),(16,'Gin','Description...',3),(17,'Rum','Description...',3),(18,'Brandy','Description...',3),(19,'Tequila','Description...',3),(20,'Vodka','Description...',3),(21,'Whiskey','Description...',3);
/*!40000 ALTER TABLE `tblsubcategory` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=#OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=#OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=#OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=#OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=#OLD_SQL_NOTES */;
-- Dump completed on 2019-05-12 13:15:55

how can i change with timestamp mysql in a date

I have here MySQL code for my table but I want to change this date but I do not want time but just date what should I do I have already searched a lot on the internet but still found nothing. and I also have a week overview here how I would apply that.
I hope you can help me
regards stefaan
``-- phpMyAdmin SQL Dump
-- version 4.4.14
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Dec 12, 2017 at 10:59 AM
-- Server version: 5.6.26
-- PHP Version: 5.5.28
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `phpcurdpdo`
--
-- --------------------------------------------------------
--
-- Table structure for table `tblusers`
--
CREATE TABLE IF NOT EXISTS `tblusers` (
`id` int(11) NOT NULL,
`Auditeur` varchar(150) NOT NULL,
`Zone` varchar(120) NOT NULL,
`NOKOK01` char(11) NOT NULL,
`NOKOK02` char(11) NOT NULL,
`NOKOK03` char(11) NOT NULL,
`NOKOK04` char(11) NOT NULL,
`Bericht` varchar(255) NOT NULL,
`PostingDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`Week` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1;
--
-- Dumping data for table `tblusers`
--
INSERT INTO `tblusers` (`id`, `Auditeur`, `Zone`, `NOKOK01`, `NOKOK02`, `NOKOK03`, `NOKOK04`, `Bericht`, `PostingDate`) VALUES
(1, 'Stefaan', 'Zone 2060', 'NOK', 'OK', 'OK', 'NOK', 'graag een verandering', '2017-12-12 06:27:53');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `tblusers`
--
ALTER TABLE `tblusers`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `tblusers`
--
ALTER TABLE `tblusers`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=7;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;

MySQL does not recognize all UTF-8 characters

I am working with MySQL server, where I need to write/read some content contains latin characters like čćšž, but for some reason my database can not store č and ć characters.
As far as I know those characters should belong inside utf8_general_ci.
I added this to my.cnf file:
[mysqld]
init_connect='SET collation_connection = utf8_general_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_general_ci
skip-character-set-client-handshake
Take a look at this picture with all encoding:
I use SOURCE command to import my database to server. Here is content of SQL dump:
SET NAMES utf8;
/*!40101 SET SQL_MODE=''*/;
/*!40014 SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET #OLD_SQL_NOTES=##SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`horoskopium` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
USE `horoskopium`;
/*Table structure for table `day` */
DROP TABLE IF EXISTS `day`;
CREATE TABLE `day` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`text` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=85 DEFAULT CHARSET=utf8;
/*Table structure for table `love` */
DROP TABLE IF EXISTS `love`;
CREATE TABLE `love` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`text` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=97 DEFAULT CHARSET=utf8;
/*Table structure for table `month` */
DROP TABLE IF EXISTS `month`;
CREATE TABLE `month` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`text` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8;
/*Table structure for table `week` */
DROP TABLE IF EXISTS `week`;
CREATE TABLE `week` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`text` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=49 DEFAULT CHARSET=utf8;
/*!40101 SET SQL_MODE=#OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=#OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=#OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=#OLD_SQL_NOTES */;
How I can solve this?
You should use utfmb4. I'm pretty sure it'll fix this.
https://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html
Utf8_general_ci or utf8mb4 or...?

Slow MySQL Query "copying to tmp table", help re-writing it

This mysql query is extremely slow, when I look at the query it is "copying to tmp table". These tables are very large especially search_attribute (79 million rows) and search_attribute_values (350,000 rows)
SELECT attributenames.name, search_attribute_values.value
FROM attributenames, categorysearchattributes, search_attribute, search_attribute_values
WHERE
categorysearchattributes.attributeid = attributenames.attributeid AND categorysearchattributes.categoryid = 4800 AND
categorysearchattributes.attributeid = search_attribute.attributeid AND
search_attribute.valueid = search_attribute_values.valueid AND
attributenames.localeid = 1
GROUP BY search_attribute.valueid
Here is a picture of the EXPLAIN of the query
Here is my database schema
-- MySQL dump 10.13 Distrib 5.5.46, for debian-linux-gnu (x86_64)
--
-- Host: localhost Database:
-- ------------------------------------------------------
-- Server version 5.5.46-0ubuntu0.14.04.2
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET #OLD_TIME_ZONE=##TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET #OLD_SQL_NOTES=##SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `attributenames`
--
DROP TABLE IF EXISTS `attributenames`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `attributenames` (
`attributeid` bigint(20) NOT NULL DEFAULT '0',
`name` varchar(110) NOT NULL DEFAULT '',
`localeid` int(11) NOT NULL DEFAULT '0',
KEY `attributenames_attributeID` (`attributeid`),
KEY `attributenames_localeID` (`localeid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Table structure for table `categorysearchattributes`
--
DROP TABLE IF EXISTS `categorysearchattributes`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `categorysearchattributes` (
`categoryid` int(11) NOT NULL DEFAULT '0',
`attributeid` bigint(20) NOT NULL DEFAULT '0',
`isactive` tinyint(1) NOT NULL DEFAULT '1',
KEY `caterysearchattributes_aID` (`attributeid`),
KEY `caterysearchattributes_cID` (`categoryid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Table structure for table `product`
--
DROP TABLE IF EXISTS `product`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `product` (
`productid` int(11) NOT NULL DEFAULT '0',
`manufacturerid` int(11) NOT NULL DEFAULT '0',
`isactive` tinyint(1) NOT NULL DEFAULT '1',
`mfgpartno` varchar(70) NOT NULL DEFAULT '',
`categoryid` int(11) NOT NULL DEFAULT '0',
`isaccessory` tinyint(1) NOT NULL DEFAULT '0',
`equivalency` double NOT NULL DEFAULT '0',
`creationdate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`modifieddate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`lastupdated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`productid`),
KEY `product_manufacturerID` (`manufacturerid`),
KEY `product_categoryID` (`categoryid`),
KEY `product_mfgPartNo` (`mfgpartno`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Table structure for table `search_attribute`
--
DROP TABLE IF EXISTS `search_attribute`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `search_attribute` (
`productid` int(11) NOT NULL DEFAULT '0',
`attributeid` bigint(20) NOT NULL DEFAULT '0',
`valueid` int(11) NOT NULL DEFAULT '0',
`localeid` int(11) NOT NULL DEFAULT '0',
`setnumber` tinyint(2) NOT NULL DEFAULT '0',
`isactive` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`productid`,`localeid`,`attributeid`,`setnumber`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Table structure for table `search_attribute_values`
--
DROP TABLE IF EXISTS `search_attribute_values`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `search_attribute_values` (
`valueid` int(11) NOT NULL DEFAULT '0',
`value` varchar(255) NOT NULL DEFAULT '',
`absolutevalue` double NOT NULL DEFAULT '0',
`unitid` int(11) NOT NULL DEFAULT '0',
`isabsolute` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`valueid`),
KEY `search_attrval_value` (`value`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = #saved_cs_client */;
Added attributeid_valueid index
By looking at the EXPLAIN query in the picture, the table search_attribute is doing a full table scan i.e. not using indexes at all.
Adding index to valueid column of search_attribute table should make it faster. Give it a try and share your results after adding index.
ALTER TABLE `search_attribute` ADD KEY `idx_valueid` (`valueid`);
Please try the combinations of suggestions below.