SQL - update columns takes time more than 5 seconds - mysql

I have the following query with tables:
tblrevrankreport
CREATE TABLE `tblrevrankreport` ( `id` bigint(20) NOT NULL auto_increment, `ndate` date NOT NULL, `tid` varchar(50) default '0', `transid` varchar(30) default NULL, `rmno` varchar(10) NOT NULL, `rmdesc` text, `rmcat` varchar(30) default NULL, `rmcatdesc` varchar(30) default NULL, `rmtariff` varchar(50) default NULL, `rmtariffdesc` text, `marketcode` varchar(50) default NULL, `marketdesc` text, `cindate` date default NULL, `coutdate` date default NULL, `nyts` int(10) default '0', `noofadult` int(10) default '0', `noofchild` int(10) default '0', `mulrate` varchar(10) default 'False', `revamt` double(20,6) default '0.000000', `othamt` double(20,6) default '0.000000', `lastmod` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `Company` varchar(200) default '', `xDate` date default NULL, PRIMARY KEY (`id`,`ndate`,`rmno`), UNIQUE KEY `id` (`id`))
tblcustomerinfohistory
CREATE TABLE `tblcustomerinfohistory` ( `ID` varchar(200) default '', `TransactionID` varchar(200) default '', `ConfirmationNo` varchar(200) default '', `ConfirmationDate` date default NULL, `ReservationNo` varchar(200) default '', `GFNo` varchar(200) default '', `ProcessBy` varchar(200) default '', `UserName` varchar(200) default '', `Room_No` varchar(200) default '', `RoomCat` varchar(200) default '', `Room_Tariff` varchar(200) default '', `RTC` varchar(200) default '', `ActionRTC` varchar(200) default 'False', `LastName` varchar(300) default '', `FirstName` varchar(300) default '', `MiddleName` varchar(300) default '', `Title` varchar(200) default '', `Country` varchar(200) default '', `xLanguage` varchar(200) default '', `VIP` varchar(200) default '', `PhoneNo` varchar(200) default '', `Agent` varchar(200) default '', `Company` varchar(200) default '', `xCompanyCode` varchar(100) default '', `xGroup` varchar(200) default '', `Source` varchar(200) default '', `CellNo` varchar(200) default '', `CInDate` date default NULL, `COutDate` date default NULL, `Nights` bigint(20) default '0', `NoOfRooms` bigint(20) default '0', `NoOfAdult` bigint(20) default '0', `NoOfChild` bigint(20) default '0', `RateCode` varchar(200) default '', `ArrivalTime` varchar(200) default '', `DepartureTime` varchar(200) default '', `Packages` varchar(200) default '', `BlockCode` varchar(200) default '', `xCurrency` varchar(200) default '', `FixedRate` varchar(200) default '', `ResType` varchar(200) default '', `Market` varchar(200) default '', `Source2` varchar(200) default '', `Origin` varchar(200) default '', `PaymentType` varchar(200) default '', `CCNo` varchar(200) default '', `ExpDate` varchar(200) default '0', `PickUpReqd` varchar(200) default '', `SCode1` varchar(200) default '', `CCode1` varchar(200) default '', `PickUpTime` varchar(200) default '', `DropOffReqd` varchar(200) default '', `SCode2` varchar(200) default '', `CCode2` varchar(200) default '', `DropOffTime` varchar(200) default '', `NoPost` varchar(200) default '', `Stat` varchar(200) default '', `ReservedType` varchar(200) default '', `BusSource` varchar(200) default '', `HomeAdd` varchar(200) default '', `Remarks` varchar(200) default '', `EMail` varchar(200) default '', `AmountDue` decimal(30,2) default '0.00', `TransType` varchar(200) default '', `GFNServices` varchar(5000) default '', `GFNMeals` varchar(5000) default '', `GFNRoom` varchar(5000) default '', `GFNOthers` varchar(5000) default '', `GFComment` varchar(5000) default '', `GFCommentOPT` varchar(5000) default '', `FlightNo` varchar(200) default '', `FlightArr` date default NULL, `FlightArrT` varchar(200) default '0', `FlightNoDep` varchar(200) default NULL, `FlightDepD` date default NULL, `FlightDepT` varchar(200) default '0', `DiscountAmount` double(30,2) default '0.00', `DiscPercentage` bigint(20) default '0', `MealsRem` varchar(200) default '', `xRemarks` varchar(200) default '', `xComments` varchar(800) default '', `BFStat` varchar(200) default '', `BFAd` bigint(20) default '0', `BFCh` bigint(20) default '0', `LNStat` varchar(200) default '', `LNAd` bigint(20) default '0', `LNCh` bigint(20) default '0', `DNStat` varchar(200) default '', `DNAd` bigint(20) default '0', `DNCh` bigint(20) default '0', `FullBoard` varchar(200) default '', `CardType` varchar(200) default '', `CardNo1` varchar(200) default '', `CardNo2` varchar(200) default '', `CardNo3` varchar(200) default '', `CardNo4` varchar(200) default '', `MachineNo` varchar(200) default '', `TraceRemarks` varchar(200) default '', `TransFer` double(20,0) default '0', `NewTrans` varchar(200) default '', `PromoRate` double(30,2) default '0.00', `ExtendCon` varchar(200) default '0', `ExtendNights` double(30,2) default '0.00', `OptionDate` date default NULL, `ReservePayment` decimal(40,2) default '0.00', `OptionOverride` varchar(200) default 'False', `PersonOverride` varchar(200) default '', `DateOverride` varchar(200) default '', `PerExtendDate` varchar(200) default '', `DateExtendD` varchar(200) default '', `ModePay` varchar(200) default '', `CNP` varchar(200) default '', `SourceToPay` varchar(200) default '', `NSBilling` varchar(200) default '', `NSAmount` double(30,2) default '0.00', `NSDiscAmount` double(30,2) default '0.00', `NSOptType` varchar(200) default '', `NSOptNights` varchar(200) default '', `NSRemarks` varchar(200) default '', `CancelledDate` date default NULL, `CancelledPerson` varchar(200) default '', `RoomCleared` varchar(50) default '', `GPassport` varchar(100) default '', `Accompany1` varchar(200) default '', `Accompany2` varchar(200) default '', `Accompany3` varchar(200) default '', `Accompany4` varchar(200) default '', `Accompany5` varchar(200) default '', `Accompany6` varchar(200) default '', `AccompanyF1` varchar(70) default '', `AccompanyF2` varchar(70) default '', `AccompanyF3` varchar(70) default '', `AccompanyF4` varchar(70) default '', `AccompanyF5` varchar(70) default '', `AccompanyF6` varchar(70) default '', `AccompanyM1` varchar(70) default '', `AccompanyM2` varchar(70) default '', `AccompanyM3` varchar(70) default '', `AccompanyM4` varchar(70) default '', `AccompanyM5` varchar(70) default '', `AccompanyM6` varchar(70) default '', `AccompanyNo1` varchar(100) default '', `AccompanyNo2` varchar(100) default '', `AccompanyNo3` varchar(100) default '', `AccompanyNo4` varchar(100) default '', `AccompanyNo5` varchar(100) default '', `AccompanyNo6` varchar(100) default '', `MultipleRate` varchar(200) default 'False', `TransferRoomRes` varchar(200) default '', `RateSetup` varchar(200) default 'Night', `BookingRef` varchar(300) default '', `TimeShareCode` varchar(300) default '', `GuestBalance` decimal(30,2) default '0.00', `stayondate` date default NULL, `CheckInTime` varchar(20) default NULL, `isDORM` varchar(10) default '0', `PPV_No` varchar(50) default '', `AccountOf` varchar(200) default '', `CountryMain` varchar(50) default NULL, `PlateNo` varchar(100) default '', `Revenue` double(40,6) default '0.000000', `CPlateNo` varchar(100) default '', `xOCCUPATION` varchar(100) default '', `WithSC` varchar(5) default '0', `allocation` int(5) default '0', `NoOfSenior` int(10) default '0', `RmVatExempt` varchar(10) default 'False', `CINFolioNo` varchar(200) default '', `intLoad` int(1) default '0', `caName` varchar(200) default '', `dwh_ID` varchar(200) default '', `WinStat` varchar(100) default '', `JuruScript` varchar(300) default '', `intLoad2` int(4) default '0', `xuseraccess` varchar(50) default '', `xuseraccess2` varchar(50) default '', `xDate` date default NULL, `xID` int(11) NOT NULL auto_increment, PRIMARY KEY (`xID`))
tbltransactionpostingdumy
CREATE TABLE `tbltransactionpostingdumy` ( `id` varchar(40) default NULL, `GuestNO` varchar(200) default NULL, `RoomNO` varchar(200) default NULL, `trCode` varchar(200) default NULL, `Description` varchar(200) default NULL, `Amount` decimal(40,6) default '0.000000', `Qty` double(30,2) default NULL, `Win` varchar(20) default NULL, `CheckNO` varchar(200) default NULL, `refno` text, `XPOS` double(200,0) default '1', `Xdate` date default NULL, `roomdate` date default NULL, `roomadd` int(20) default '0', `settleCode` int(20) default '0', `Rout` int(20) default '0', `COut` int(20) default '0', `Supplement` text, `xuser` varchar(200) default NULL, `xTime` varchar(200) default '0', `GuestName` varchar(200) default '', `Source` varchar(200) default '', `TransferCharge` varchar(200) default '0', `AR` varchar(200) default 'False', `ARPayment` varchar(200) default 'False', `ChitNo` varchar(200) default '', `ORnumberNO` varchar(200) default '', `Correction` varchar(200) default 'False', `TRUE_DATE` date default NULL, `POS_QTY` bigint(10) default '0', `POS_TOTAL` decimal(30,2) default '0.00', `POS_AMTDUE` decimal(30,2) default '0.00', `POS_VAT` decimal(30,2) default '0.00', `POS_SC` decimal(30,2) default '0.00', `POS_WID` varchar(100) default '', `POS_WNAME` varchar(300) default '', `POS_CID` varchar(100) default '', `POS_CNAME` varchar(300) default '', `POST_STAT` varchar(100) default 'HMS', `MainTransNo` varchar(20) default '0', `TransferDesc` varchar(20) default '', `ConfiNo` varchar(20) default '', `isAdvBill` varchar(20) default '', `CCNum` varchar(200) default NULL, `CCName` varchar(200) default NULL, `HName` varchar(200) default NULL, `ExpDate` date default NULL, `AuthCode` varchar(200) default NULL, `isSOA` varchar(100) default 'NO', `SENDBILLTO` varchar(50) default NULL, `WithVat` tinyint(5) default '1', `WithSC` tinyint(5) default '1', `AMT_VAT` decimal(30,6) default '0.000000', `AMT_SC` decimal(30,6) default '0.000000', `CL_TRNF` tinyint(5) default '0', `G_ID` varchar(30) default '', `G_NAME` varchar(100) default '', `G_TRNO` varchar(5) default '', `SpecialCase` varchar(10) default '0', `SD_Amount` decimal(40,6) default '0.000000', `SD_Vat` decimal(40,6) default '0.000000', `SeniorDis` varchar(10) default '0', `SeniorPerc` decimal(40,6) default '0.000000', `withLT` tinyint(5) default '0', `amt_LT` decimal(30,6) default '0.000000', `WithSD` varchar(5) default '0', `AMT_SENIORDISC` decimal(30,6) default '0.000000', `xCat` varchar(200) default '', `SC_PERC` double(40,6) default '0.000000', `disctype` varchar(200) default '', `origAmount` decimal(40,2) default '0.00', `vatExempt` decimal(40,6) default '0.000000', `SENDBILLTOCODE` varchar(200) default '', `caID` int(100) default NULL, `CaTrans` varchar(100) default '', `ARCollections` tinyint(1) default '0', `vatExemptSales` decimal(40,6) default '0.000000', `xdatetime` timestamp NULL default CURRENT_TIMESTAMP, `baseCharge` decimal(40,6) default '0.000000', `SRP` decimal(40,6) default '0.000000', `seniorID` varchar(40) default '', `Machinenum` varchar(50) default '', `fullname` varchar(200) default '', KEY `idx_date` (`Xdate`), KEY `idx_guestno` (`GuestNO`), KEY `idx_id` (`id`), KEY `idx_machine` (`Machinenum`), KEY `idx_roomno` (`RoomNO`), KEY `idx_trcode` (`trCode`))
Deleted the records first from '2017-04-01' to '2017-04-30':
DELETE FROM tblrevrankreport
WHERE xdate BETWEEN '2017-04-01' AND '2017-04-30';
Then get the records and save it:
INSERT INTO tblrevrankreport (ndate, xDate, tid, transid, rmno, rmcat, rmcatdesc, rmtariff, marketdesc, cindate, coutdate, mulrate, revamt, othamt, Company)
SELECT
a.xDate, a.xDate, b.id, a.guestno, a.roomno,
b.RoomCat, b.roomcat, b.Room_Tariff,
b.Market, b.CInDate, b.coutdate, b.MultipleRate,
IF(c.ratecode = 1, (a.amount - (a.AMT_VAT + a.AMT_SC + a.AMT_LT)), ''),
IF(c.ratecode <> 1, (a.amount - (a.AMT_VAT + a.AMT_SC + a.AMT_LT)), ''),
b.Company
FROM
tbltransactionpostingdumy a
LEFT JOIN
tblcustomerinfo b ON a.MaintransNo = b.transactionID
LEFT JOIN
tblreftransaction c ON a.trcode = c.xcode
WHERE
(a.xDate BETWEEN '2017-04-01' AND '2017-04-30')
AND c.xcat = 'ROOM CHARGE';
Then the problem happens here:
UPDATE
tblrevrankreport b, tblcustomerinfohistory a
SET
b.nyts = 1,
b.NoOfAdult = a.NoOfAdult,
b.NoOfChild = a.NoOfChild
WHERE
b.xdate = '2017-04-01'
AND '2017-04-30')
AND b.COutDate > b.xdate
AND b.rmcat <> 'PQ'
AND b.transid = a.TransactionID
AND b.xdate = a.Xdate;
The last query took much time, the total records to be updated in tblrevrankreport is 5242.
Is there another to improve it?
Thanks!

Related

Bad performance in MYSQL 5.7 after Upgrade from 5.6.27

I've got a query like the following:
SELECT * FROM table_a
LEFT JOIN table_b ON table_a.nr = table_b.a_nr
ORDER BY table_b.name
Under MYSQL 5.7.9, this query takes about 120sek.
Under 5.6.27 "only" ~25 sek. There are 500000 rows in table_a. Why is 5.7.9 that slow?
I know, Mysql can not use an index for sorting, cause of the joined column.
I made test with InnoDB and the MYISAM engine with the same result.
Any suggestions?
EDIT
CREATE TABLE `table_a` (
`NR` CHAR(60) NOT NULL DEFAULT '',
`LIEFNR` CHAR(6) NOT NULL DEFAULT '',
`BEZ1` CHAR(80) NOT NULL DEFAULT '',
`BEZ2` CHAR(40) NOT NULL DEFAULT '',
`SBEZ1` CHAR(80) NOT NULL DEFAULT '',
`SBEZ2` CHAR(40) NOT NULL DEFAULT '',
`MENGENEINH` CHAR(5) NOT NULL DEFAULT '',
`VKPREIS` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`PREISEINH` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`PREISEINH_IST` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`PREISEINHVK` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`PREISEINHVK_IST` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`EAN` CHAR(14) NOT NULL DEFAULT '',
`EANUSER` CHAR(14) NOT NULL DEFAULT '',
`EKPREIS` DECIMAL(13,5) NOT NULL DEFAULT '0.00000',
`LISTENEKPREIS` DECIMAL(13,5) NOT NULL DEFAULT '0.00000',
`BESTELLNR` CHAR(25) NOT NULL DEFAULT '',
`LANGTEXT` longtext,
`KATSEITE` CHAR(5) NOT NULL DEFAULT '',
`HERSTARTNR` CHAR(50) NOT NULL DEFAULT '',
`HWGR` CHAR(50) NOT NULL DEFAULT '',
`WGR` CHAR(50) NOT NULL DEFAULT '',
`MWST` CHAR(6) NOT NULL DEFAULT '',
`EKRABGR` CHAR(3) NOT NULL DEFAULT '',
`VKRABGR` CHAR(3) NOT NULL DEFAULT '',
`VERPAMENGE` DECIMAL(5,0) NOT NULL DEFAULT '0',
`PACKINH` DECIMAL(7,0) NOT NULL DEFAULT '0',
`MARK` CHAR(1) NOT NULL DEFAULT '',
`UEBERGABE` CHAR(1) NOT NULL DEFAULT '',
`GEWICHT` DECIMAL(10,3) NOT NULL DEFAULT '0.000',
`RABATT` DECIMAL(6,2) NOT NULL DEFAULT '0.00',
`ARTUID` CHAR(10) NOT NULL DEFAULT '',
`PREINH2` CHAR(5) NOT NULL DEFAULT '',
`NPREIS2` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`PREINH3` CHAR(5) NOT NULL DEFAULT '',
`NPREIS3` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`PREINH4` CHAR(5) NOT NULL DEFAULT '',
`NPREIS4` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`PREINH5` CHAR(5) NOT NULL DEFAULT '',
`NPREIS5` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`NPREISFAK` DECIMAL(13,5) NOT NULL DEFAULT '0.00000',
`EKSTAFM1` CHAR(5) NOT NULL DEFAULT '',
`EKSTAFP1` DECIMAL(13,5) NOT NULL DEFAULT '0.00000',
`EKSTAFM2` CHAR(5) NOT NULL DEFAULT '',
`EKSTAFP2` DECIMAL(13,5) NOT NULL DEFAULT '0.00000',
`EKSTAFM3` CHAR(5) NOT NULL DEFAULT '',
`EKSTAFP3` DECIMAL(13,5) NOT NULL DEFAULT '0.00000',
`EKSTAFM4` CHAR(5) NOT NULL DEFAULT '',
`EKSTAFP4` DECIMAL(13,5) NOT NULL DEFAULT '0.00000',
`EKSTAFM5` CHAR(5) NOT NULL DEFAULT '',
`EKSTAFP5` DECIMAL(13,5) NOT NULL DEFAULT '0.00000',
`EKSTAFFAK` DECIMAL(13,5) NOT NULL DEFAULT '0.00000',
`PREISEMPF` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`UMRFAKTOR` DECIMAL(12,5) NOT NULL DEFAULT '0.00000',
`LIEFILN` CHAR(13) NOT NULL DEFAULT '',
`MODE` CHAR(1) NOT NULL DEFAULT '',
`HERSTNAME` CHAR(50) NOT NULL DEFAULT '',
`VERWEIS` CHAR(30) NOT NULL DEFAULT '',
`MINDBEST` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`AENDDAT` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`ANLAGEDAT` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`LASTIMPORT` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`NOTUEBERN` CHAR(1) NOT NULL DEFAULT '',
`PERSBEZPREIS` CHAR(1) NOT NULL DEFAULT '',
`AKTUELLTEMP` CHAR(1) NOT NULL DEFAULT '',
`NICHTAKTUELL` CHAR(1) NOT NULL DEFAULT '',
`ZUSATZEAN1` CHAR(14) NOT NULL DEFAULT '',
`ZUSATZEAN2` CHAR(14) NOT NULL DEFAULT '',
`ZUSATZEAN3` CHAR(14) NOT NULL DEFAULT '',
`ZUSATZEAN4` CHAR(14) NOT NULL DEFAULT '',
`ZUSATZEAN5` CHAR(14) NOT NULL DEFAULT '',
`AUSLAUFARTI` CHAR(1) NOT NULL DEFAULT '',
`PAFAKTOR` DECIMAL(13,6) NOT NULL DEFAULT '0.000000',
`PREISFOKUS` CHAR(1) NOT NULL DEFAULT '',
`IMPORTKENNZ` CHAR(1) NOT NULL DEFAULT '',
`MATCHARTNR` CHAR(40) NOT NULL DEFAULT '',
`EXPORTFREIGABE` CHAR(1) NOT NULL DEFAULT '',
`MD5` CHAR(32) NOT NULL DEFAULT '',
`KEYWORDS` longtext,
`SHOPTEXT` longtext,
`BEMERKUNG` CHAR(80) NOT NULL DEFAULT '',
`SYS_UID` CHAR(10) NOT NULL DEFAULT '',
`SYS_DATE` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY `P_ARTI01` (`SYS_UID`),
KEY `P_ARTI02` (`LIEFNR`,`NR`,`MD5`),
KEY `P_ARTI03` (`LIEFNR`,`BEZ1`),
KEY `P_ARTI04` (`LIEFNR`,`HWGR`,`WGR`),
KEY `P_ARTI05` (`EAN`,`LIEFNR`),
KEY `P_ARTI06` (`AENDDAT`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
CREATE TABLE `table_b` (
`A_NR` CHAR(25) NOT NULL DEFAULT '',
`A_FNR` CHAR(25) NOT NULL DEFAULT '',
`A_NAME1` CHAR(40) NOT NULL DEFAULT '',
`A_NAME2` CHAR(40) NOT NULL DEFAULT '',
`A_EINHEIT` CHAR(2) NOT NULL DEFAULT '',
`A_MENGEING` DECIMAL(2,0) NOT NULL DEFAULT '0',
`A_VERPACK` CHAR(3) NOT NULL DEFAULT '',
`A_WGR` CHAR(3) NOT NULL DEFAULT '',
`A_WGRU` CHAR(3) NOT NULL DEFAULT '',
`A_ECLASS` CHAR(20) NOT NULL DEFAULT '',
`A_LAGORT` CHAR(10) NOT NULL DEFAULT '',
`A_MENGEINH` DECIMAL(6,0) NOT NULL DEFAULT '0',
`A_VK1` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_VK2` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_VK3` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_VK4` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_VK5` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_VK6` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_VK7` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_VK8` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_VK9` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_VKB1` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_VKB2` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_VKB3` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_VKB4` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_VKB5` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_VKB6` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_VKB7` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_VKB8` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_VKB9` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_VKBED1` CHAR(18) NOT NULL DEFAULT '',
`A_VKBED2` CHAR(18) NOT NULL DEFAULT '',
`A_VKBED3` CHAR(18) NOT NULL DEFAULT '',
`A_VKBED4` CHAR(18) NOT NULL DEFAULT '',
`A_VKBED5` CHAR(18) NOT NULL DEFAULT '',
`A_VKBED6` CHAR(18) NOT NULL DEFAULT '',
`A_VKBED7` CHAR(18) NOT NULL DEFAULT '',
`A_VKBED8` CHAR(18) NOT NULL DEFAULT '',
`A_VKBED9` CHAR(18) NOT NULL DEFAULT '',
`A_ERLDM1` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_ERLDM2` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_ERLDM3` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_ERLDM4` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_ERLDM5` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_ERLDM6` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_ERLDM7` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_ERLDM8` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_ERLDM9` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_ERLPRO1` DECIMAL(7,3) NOT NULL DEFAULT '0.000',
`A_ERLPRO2` DECIMAL(7,3) NOT NULL DEFAULT '0.000',
`A_ERLPRO3` DECIMAL(7,3) NOT NULL DEFAULT '0.000',
`A_ERLPRO4` DECIMAL(7,3) NOT NULL DEFAULT '0.000',
`A_ERLPRO5` DECIMAL(7,3) NOT NULL DEFAULT '0.000',
`A_ERLPRO6` DECIMAL(7,3) NOT NULL DEFAULT '0.000',
`A_ERLPRO7` DECIMAL(7,3) NOT NULL DEFAULT '0.000',
`A_ERLPRO8` DECIMAL(7,3) NOT NULL DEFAULT '0.000',
`A_ERLPRO9` DECIMAL(7,3) NOT NULL DEFAULT '0.000',
`A_LIEFER1` CHAR(6) NOT NULL DEFAULT '',
`A_LIEFER2` CHAR(6) NOT NULL DEFAULT '',
`A_LIEFER3` CHAR(6) NOT NULL DEFAULT '',
`A_LIEFER4` CHAR(6) NOT NULL DEFAULT '',
`A_LIEFER5` CHAR(6) NOT NULL DEFAULT '',
`A_EK1` DECIMAL(13,5) NOT NULL DEFAULT '0.00000',
`A_EK2` DECIMAL(13,5) NOT NULL DEFAULT '0.00000',
`A_EK3` DECIMAL(13,5) NOT NULL DEFAULT '0.00000',
`A_EK4` DECIMAL(13,5) NOT NULL DEFAULT '0.00000',
`A_EK5` DECIMAL(13,5) NOT NULL DEFAULT '0.00000',
`A_EKVKPROZ` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_BON1` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_BON2` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_BON3` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_BON4` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_BON5` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_RAB1` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_RAB2` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_RAB3` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_RAB4` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_RAB5` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_BESTNR1` CHAR(60) NOT NULL DEFAULT '',
`A_BESTNR2` CHAR(60) NOT NULL DEFAULT '',
`A_BESTNR3` CHAR(60) NOT NULL DEFAULT '',
`A_BESTNR4` CHAR(60) NOT NULL DEFAULT '',
`A_BESTNR5` CHAR(60) NOT NULL DEFAULT '',
`A_BESDAT1` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`A_BESDAT2` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`A_BESDAT3` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`A_BESDAT4` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`A_BESDAT5` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`A_EAN` CHAR(14) NOT NULL DEFAULT '',
`A_POSKEN` CHAR(4) NOT NULL DEFAULT '',
`A_BESTAND` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_MAXBE` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_MELDEBE` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_UMSASTK` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_UMSJA` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_UMSLF` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_UMSQU` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_UMSVJ` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_CNTLF` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_CNTJA` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_CNTQU` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_CNTVJ` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_EKLF` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_EKQU` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_EKJA` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_EKSLF` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_EKSQU` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_EKSJA` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_UMSDATUM` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`A_EKDATUM` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`A_ANLAGE` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`A_LTZAEND` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`A_LDAT` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`A_LZEIT` CHAR(5) NOT NULL DEFAULT '',
`A_MWSTSCHL` CHAR(2) NOT NULL DEFAULT '',
`A_VSTSCHL` CHAR(2) NOT NULL DEFAULT '',
`A_INVENTUR` CHAR(3) NOT NULL DEFAULT '',
`A_GERAET` CHAR(1) NOT NULL DEFAULT '',
`A_SERIENNR` CHAR(1) NOT NULL DEFAULT '',
`A_INOUTPUT` CHAR(1) NOT NULL DEFAULT '',
`A_FAKTURA` CHAR(1) NOT NULL DEFAULT '',
`A_RABATT` CHAR(1) NOT NULL DEFAULT '',
`A_RABGR1` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_RABGR2` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_RABGR3` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_RABGR4` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_RABGR5` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_ERLKTO` CHAR(3) NOT NULL DEFAULT '',
`DELETED` CHAR(1) NOT NULL DEFAULT '',
`A_SNAME1` CHAR(40) NOT NULL DEFAULT '',
`A_SNAME2` CHAR(40) NOT NULL DEFAULT '',
`A_SEINHEIT` CHAR(2) NOT NULL DEFAULT '',
`A_SPRACHE` CHAR(3) NOT NULL DEFAULT '',
`A_URLAND` CHAR(3) NOT NULL DEFAULT '',
`A_LANGTEXT` longtext,
`A_LANGTEXTANSI` longtext,
`A_GEBINDE` CHAR(3) NOT NULL DEFAULT '',
`A_POSANZ` DECIMAL(8,2) NOT NULL DEFAULT '0.00',
`A_DATANORM` CHAR(25) NOT NULL DEFAULT '',
`A_HANDGW` DECIMAL(9,4) NOT NULL DEFAULT '0.0000',
`A_ARTNR` CHAR(25) NOT NULL DEFAULT '',
`A_ARTIPOS` CHAR(6) NOT NULL DEFAULT '',
`A_LAGPOS` CHAR(8) NOT NULL DEFAULT '',
`A_SERLKTO` CHAR(3) NOT NULL DEFAULT '',
`A_EGKTO` CHAR(3) NOT NULL DEFAULT '',
`A_EKDURCH` DECIMAL(13,5) NOT NULL DEFAULT '0.00000',
`A_DBESTAND` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_RESBEST` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_KZMENGE` CHAR(1) NOT NULL DEFAULT '',
`A_KZFEST1` DECIMAL(10,3) NOT NULL DEFAULT '0.000',
`A_KZFEST2` DECIMAL(10,3) NOT NULL DEFAULT '0.000',
`A_KZFEST3` DECIMAL(10,3) NOT NULL DEFAULT '0.000',
`A_STDVERR` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_EKVORJA` DECIMAL(13,5) NOT NULL DEFAULT '0.00000',
`A_PROZFRA` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_BESZEIT` DECIMAL(4,0) NOT NULL DEFAULT '0',
`A_PROVSATZ` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_LADELIST` CHAR(1) NOT NULL DEFAULT '',
`A_PAVKN1` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_PAVKN2` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_PAVKN3` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_PAVKN4` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_PAVKN5` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_PAVKB1` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_PAVKB2` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_PAVKB3` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_PAVKB4` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_PAVKB5` DECIMAL(10,2) NOT NULL DEFAULT '0.00',
`A_PRODSC` CHAR(4) NOT NULL DEFAULT '',
`A_PRODZEIT` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_PRODLI` CHAR(2) NOT NULL DEFAULT '',
`A_MINPROV` DECIMAL(7,2) NOT NULL DEFAULT '0.00',
`A_TYP` CHAR(1) NOT NULL DEFAULT '',
`A_EKSTK` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_EKDM` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_STFAKTOR` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_ABSATZ` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_KVER` CHAR(1) NOT NULL DEFAULT '',
`A_ABESTAND` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_LOHNVJ` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_LOHNSUMM` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_SUCHBEGRIFF` CHAR(40) NOT NULL DEFAULT '',
`A_GFAKTOR` DECIMAL(8,3) NOT NULL DEFAULT '0.000',
`A_GMEINH` CHAR(2) NOT NULL DEFAULT '',
`A_IBEWERT` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_IBEWSTUND` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_LOHNSTD` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_MASCHSTD` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_SUCHTEXT` longtext,
`A_SUCHTEXTANSI` longtext,
`A_GERART` CHAR(3) NOT NULL DEFAULT '',
`A_LAGER` CHAR(1) NOT NULL DEFAULT '',
`A_BEMERKUNG` CHAR(60) NOT NULL DEFAULT '',
`A_KEINBEST` CHAR(1) NOT NULL DEFAULT '',
`A_PRODUKTION` CHAR(1) NOT NULL DEFAULT '',
`A_SKFJN` CHAR(1) NOT NULL DEFAULT '',
`A_AKLART1` CHAR(4) NOT NULL DEFAULT '',
`A_AKLART2` CHAR(4) NOT NULL DEFAULT '',
`A_AKLART3` CHAR(4) NOT NULL DEFAULT '',
`A_AKLART4` CHAR(4) NOT NULL DEFAULT '',
`A_AKLART5` CHAR(4) NOT NULL DEFAULT '',
`A_AKLART6` CHAR(4) NOT NULL DEFAULT '',
`A_AKLART7` CHAR(4) NOT NULL DEFAULT '',
`A_AKLART8` CHAR(4) NOT NULL DEFAULT '',
`A_AKLART9` CHAR(4) NOT NULL DEFAULT '',
`A_AKSATZ1` DECIMAL(8,4) NOT NULL DEFAULT '0.0000',
`A_AKSATZ2` DECIMAL(8,4) NOT NULL DEFAULT '0.0000',
`A_AKSATZ3` DECIMAL(8,4) NOT NULL DEFAULT '0.0000',
`A_AKSATZ4` DECIMAL(8,4) NOT NULL DEFAULT '0.0000',
`A_AKSATZ5` DECIMAL(8,4) NOT NULL DEFAULT '0.0000',
`A_AKSATZ6` DECIMAL(8,4) NOT NULL DEFAULT '0.0000',
`A_AKSATZ7` DECIMAL(8,4) NOT NULL DEFAULT '0.0000',
`A_AKSATZ8` DECIMAL(8,4) NOT NULL DEFAULT '0.0000',
`A_AKSATZ9` DECIMAL(8,4) NOT NULL DEFAULT '0.0000',
`A_AKSOLL1` CHAR(20) NOT NULL DEFAULT '',
`A_AKSOLL2` CHAR(20) NOT NULL DEFAULT '',
`A_AKSOLL3` CHAR(20) NOT NULL DEFAULT '',
`A_AKSOLL4` CHAR(20) NOT NULL DEFAULT '',
`A_AKSOLL5` CHAR(20) NOT NULL DEFAULT '',
`A_AKSOLL6` CHAR(20) NOT NULL DEFAULT '',
`A_AKSOLL7` CHAR(20) NOT NULL DEFAULT '',
`A_AKSOLL8` CHAR(20) NOT NULL DEFAULT '',
`A_AKSOLL9` CHAR(20) NOT NULL DEFAULT '',
`A_INAKTIV` CHAR(1) NOT NULL DEFAULT '',
`A_AUTOINAKTIV` CHAR(1) NOT NULL DEFAULT '',
`A_STCKOPT` CHAR(1) NOT NULL DEFAULT '',
`A_FILIALE` CHAR(2) NOT NULL DEFAULT '',
`A_PRODMENG` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_SONDERART` CHAR(1) NOT NULL DEFAULT '',
`A_BETONREZEPT` DECIMAL(3,0) NOT NULL DEFAULT '0',
`A_UEBERDECKUNG` DECIMAL(3,1) NOT NULL DEFAULT '0.0',
`A_UEBERDECKUNG_R` DECIMAL(3,1) NOT NULL DEFAULT '0.0',
`A_UEBERDECKUNG_O` DECIMAL(3,1) NOT NULL DEFAULT '0.0',
`A_UEBERDECKUNG_U` DECIMAL(3,1) NOT NULL DEFAULT '0.0',
`A_MENGEFORMEN` DECIMAL(3,0) NOT NULL DEFAULT '0',
`A_TRANSLAGER` CHAR(2) NOT NULL DEFAULT '',
`A_GARANTIE` DECIMAL(4,0) NOT NULL DEFAULT '0',
`A_HERSTELLERNR` CHAR(80) NOT NULL DEFAULT '',
`A_HERSTELLERNAME` CHAR(40) NOT NULL DEFAULT '',
`A_PREISFOKUS` CHAR(1) NOT NULL DEFAULT '',
`A_MINDBESTMENGE` DECIMAL(12,2) NOT NULL DEFAULT '0.00',
`A_NEUKALK` CHAR(1) NOT NULL DEFAULT '',
`A_PREISFLAG1` CHAR(1) NOT NULL DEFAULT '',
`A_PREISFLAG2` CHAR(1) NOT NULL DEFAULT '',
`A_PREISFLAG3` CHAR(1) NOT NULL DEFAULT '',
`A_KEINEXTTEXT` CHAR(1) NOT NULL DEFAULT '',
`A_ZEN_KBEZ` CHAR(1) NOT NULL DEFAULT '',
`A_SHOP` CHAR(1) NOT NULL DEFAULT '',
`A_SHOP_NOSEARCH` CHAR(1) NOT NULL DEFAULT '',
`A_SHOPTEXTKD` CHAR(1) NOT NULL DEFAULT '',
`A_SHOPTEXTKD_TITEL` CHAR(80) NOT NULL DEFAULT '',
`A_SHOPBEZ` CHAR(100) NOT NULL DEFAULT '',
`A_METATITLE` CHAR(100) NOT NULL DEFAULT '',
`A_METADESCR` CHAR(255) NOT NULL DEFAULT '',
`A_METAKEYWORDS` CHAR(255) NOT NULL DEFAULT '',
`A_GUTSCHEIN` CHAR(1) NOT NULL DEFAULT '',
`A_SHOPARTNR` CHAR(80) NOT NULL DEFAULT '',
`A_VSSF_FAKTOR` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_VSSF_VON` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`A_VSSF_BIS` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`A_VSSF_A_FAKTOR` DECIMAL(5,2) NOT NULL DEFAULT '0.00',
`A_VSSF_A_VON` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`A_VSSF_A_BIS` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`A_ERFASSER` CHAR(3) NOT NULL DEFAULT '',
`A_COLSTATUS` CHAR(1) NOT NULL DEFAULT '',
`SYS_ZENTRALE` CHAR(10) NOT NULL DEFAULT '',
`SYS_UID` CHAR(10) NOT NULL DEFAULT '',
`SYS_DATE` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY `ARTIKEL01` (`SYS_UID`),
UNIQUE KEY `ARTIKEL02` (`A_NR`),
KEY `ARTIKEL03` (`A_NAME1`,`A_NAME2`),
KEY `ARTIKEL04` (`A_DATANORM`),
KEY `ARTIKEL05` (`A_WGR`,`A_NAME1`,`A_NAME2`),
KEY `ARTIKEL06` (`A_LAGPOS`,`A_NAME1`,`A_NAME2`),
KEY `ARTIKEL07` (`A_ARTIPOS`),
KEY `ARTIKEL08` (`A_SUCHBEGRIFF`),
KEY `ARTIKEL09` (`A_EAN`),
KEY `ARTIKEL10` (`A_FILIALE`),
KEY `ARTIKEL11` (`A_FILIALE`,`A_NR`),
KEY `ARTIKEL12` (`A_INAKTIV`,`A_NR`),
KEY `ARTIKEL13` (`A_LAGER`),
KEY `ARTIKEL14` (`A_ARTNR`),
KEY `ARTIKEL15` (`A_HERSTELLERNR`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
Sometimes it's quite useful. if you are linking some documents to costumer informations, you'll have unlinked dokuments.
Use consistent definitions for columns being JOINed on.
Use VARCHAR, not CHAR unless the column is a constant length.
Use an extra table rather than putting "arrays" as columns: A_AKSOLL9 (etc).
Did you set innodb_buffer_pool_size to a reasonable value when testing InnoDB?

Auto increment it's not working

I have a problem on my website with auto increment and I can't find a way to fix it...
It works with this table:
CREATE TABLE IF NOT EXISTS `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(40) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`password` varchar(40) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`loginhash` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL,
`id_level` int(10) NOT NULL DEFAULT '1',
`random` int(10) DEFAULT '0',
`email` varchar(30) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`language` tinyint(4) NOT NULL DEFAULT '1',
`style` tinyint(4) NOT NULL DEFAULT '1',
`joined` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`lastconnect` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`lip` bigint(11) DEFAULT '0',
`downloaded` bigint(20) DEFAULT '0',
`uploaded` bigint(20) DEFAULT '0',
`avatar` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`pid` varchar(32) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`flag` tinyint(1) unsigned NOT NULL DEFAULT '0',
`topicsperpage` tinyint(3) unsigned NOT NULL DEFAULT '15',
`postsperpage` tinyint(3) unsigned NOT NULL DEFAULT '15',
`torrentsperpage` tinyint(3) unsigned NOT NULL DEFAULT '15',
`cip` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL,
`time_offset` varchar(4) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
`temp_email` varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`flags` bigint(20) unsigned NOT NULL DEFAULT '7345036',
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
KEY `id_level` (`id_level`),
KEY `pid` (`pid`),
KEY `cip` (`cip`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
But it doesn't work with this table:
CREATE TABLE IF NOT EXISTS `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(40) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`password` varchar(40) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`loginhash` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL,
`id_level` int(10) NOT NULL DEFAULT '1',
`random` int(10) DEFAULT '0',
`email` varchar(30) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`language` tinyint(4) NOT NULL DEFAULT '1',
`style` tinyint(4) NOT NULL DEFAULT '1',
`joined` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`lastconnect` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`lip` bigint(11) DEFAULT '0',
`downloaded` bigint(20) DEFAULT '0',
`uploaded` bigint(20) DEFAULT '0',
`avatar` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`pid` varchar(32) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`flag` tinyint(1) unsigned NOT NULL DEFAULT '0',
`topicsperpage` tinyint(3) unsigned NOT NULL DEFAULT '15',
`postsperpage` tinyint(3) unsigned NOT NULL DEFAULT '15',
`torrentsperpage` tinyint(3) unsigned NOT NULL DEFAULT '15',
`cip` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL,
`time_offset` varchar(4) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
`temp_email` varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`flags` bigint(20) unsigned NOT NULL DEFAULT '7345036',
`rank_switch` enum('yes','no') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',
`old_rank` varchar(12) COLLATE utf8_unicode_ci NOT NULL DEFAULT '3',
`timed_rank` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`seedbonus` decimal(5,1) NOT NULL,
`on_forum` int(11) NOT NULL DEFAULT '0',
`on_topic` int(11) NOT NULL DEFAULT '0',
`custom_title` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`invites` int(10) NOT NULL DEFAULT '0',
`invited_by` int(10) NOT NULL DEFAULT '0',
`invitedate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`donor` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',
`banfromforum` enum('yes','no') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
KEY `id_level` (`id_level`),
KEY `pid` (`pid`),
KEY `cip` (`cip`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
Can anyone tell me where the problem is?

correct mysql syntax error

please could someone tell me the problem with this syntax because mysql 5.5.32 keeps tell me about an error
CREATE TABLE `clients` (
`ID` tinyint(11) NOT NULL auto_increment,
`title` varchar(10) NOT NULL default '',
`firstName` varchar(30) NOT NULL default '',
`lastName` varchar(30) NOT NULL default '',
`address1` varchar(100) NOT NULL default '',
`address2` varchar(100) NOT NULL default '',
`town` varchar(100) NOT NULL default '',
`province` varchar(100) NOT NULL default '',
`country` varchar(40) NOT NULL default '',
`postCode` varchar(20) NOT NULL default '',
`telephone` varchar(20) NOT NULL default '',
`email` varchar(100) NOT NULL default '',
`cardNo` varchar(16) NOT NULL default '0000-00-00',
`expiryDate` date NOT NULL default '0000-00-00',
PRIMARY KEY (`ID`)
) TYPE=MyISAM COMMENT='customer table' AUTO_INCREMENT=1 ;
The keyword TYPE has been replaced by ENGINE as in
ENGINE=MyISAM
change TYPE to ENGINE like this:
CREATE TABLE `clients` (
`ID` tinyint(11) NOT NULL auto_increment,
`title` varchar(10) NOT NULL default '',
`firstName` varchar(30) NOT NULL default '',
`lastName` varchar(30) NOT NULL default '',
`address1` varchar(100) NOT NULL default '',
`address2` varchar(100) NOT NULL default '',
`town` varchar(100) NOT NULL default '',
`province` varchar(100) NOT NULL default '',
`country` varchar(40) NOT NULL default '',
`postCode` varchar(20) NOT NULL default '',
`telephone` varchar(20) NOT NULL default '',
`email` varchar(100) NOT NULL default '',
`cardNo` varchar(16) NOT NULL default '0000-00-00',
`expiryDate` date NOT NULL default '0000-00-00',
PRIMARY KEY (`ID`)
) ENGINE=MyISAM COMMENT='customer table' AUTO_INCREMENT=1 ;
MySQL 5.0 accepts TYPE or ENGINE, but above MySQL 5.1, Only ENGINE is allowed.

need help Mysql query

I am trying to achieve displaying a field in my database.
basically at the moment i have
'SELECT
historylist.artist,
historylist.ID,
artistlist.lyrics,
artistlist.ID
FROM historylist
INNER JOIN artistlist
ON historylist.ID = artistlist.ID
ORDER BY historylist.date_played DESC
LIMIT 1;'
Now this is not correct. I need to use the history list ID to link the artistlist ID. Then grab the field artistlist.lyrics. then display it. Right now when i do it like that it shows the lyrics field but its null. So i am guessing its searching historylist table
CREATE TABLE `historylist` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`songID` int(11) NOT NULL DEFAULT '0',
`filename` varchar(255) NOT NULL DEFAULT '',
`date_played` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`duration` int(11) NOT NULL DEFAULT '0',
`artist` varchar(255) NOT NULL DEFAULT '',
`title` varchar(255) NOT NULL DEFAULT '',
`album` varchar(255) NOT NULL DEFAULT '',
`albumyear` varchar(4) NOT NULL DEFAULT '',
`website` varchar(255) NOT NULL DEFAULT '',
`buycd` varchar(255) NOT NULL DEFAULT '',
`picture` varchar(255) NOT NULL DEFAULT '',
`listeners` mediumint(9) NOT NULL DEFAULT '0',
`label` varchar(100) NOT NULL DEFAULT '',
`pline` varchar(50) NOT NULL DEFAULT '',
`trackno` int(11) NOT NULL DEFAULT '0',
`composer` varchar(100) NOT NULL DEFAULT '',
`ISRC` varchar(50) NOT NULL DEFAULT '',
`catalog` varchar(50) NOT NULL DEFAULT '',
`UPC` varchar(50) NOT NULL DEFAULT '',
`feeagency` varchar(20) NOT NULL DEFAULT '',
PRIMARY KEY (`ID`),
KEY `date_played` (`date_played`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
that code above is the historylist table
this one is the
CREATE TABLE IF NOT EXISTS `artistlist` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`filename` varchar(255) NOT NULL DEFAULT '',
`diskID` int(11) NOT NULL DEFAULT '0',
`flags` varchar(10) NOT NULL DEFAULT 'NNNNNNNNNN',
`songtype` char(1) NOT NULL DEFAULT 'S',
`status` tinyint(4) NOT NULL DEFAULT '0',
`weight` double NOT NULL DEFAULT '50',
`balance` double NOT NULL DEFAULT '0',
`date_added` datetime DEFAULT NULL,
`date_played` datetime DEFAULT NULL,
`date_artist_played` datetime DEFAULT '2002-01-01 00:00:01',
`date_album_played` datetime DEFAULT '2002-01-01 00:00:01',
`date_title_played` datetime DEFAULT '2002-01-01 00:00:01',
`duration` int(11) NOT NULL DEFAULT '0',
`artist` varchar(255) NOT NULL DEFAULT '',
`title` varchar(255) NOT NULL DEFAULT '',
`album` varchar(255) NOT NULL DEFAULT '',
`label` varchar(255) NOT NULL DEFAULT '',
`pline` varchar(50) NOT NULL DEFAULT '',
`trackno` int(11) NOT NULL DEFAULT '0',
`composer` varchar(100) NOT NULL DEFAULT '',
`ISRC` varchar(50) NOT NULL DEFAULT '',
`catalog` varchar(50) NOT NULL DEFAULT '',
`UPC` varchar(50) NOT NULL DEFAULT '',
`feeagency` varchar(20) NOT NULL DEFAULT '',
`albumyear` varchar(4) NOT NULL DEFAULT '0',
`genre` varchar(20) NOT NULL DEFAULT '',
`website` varchar(255) NOT NULL DEFAULT '',
`buycd` varchar(255) NOT NULL DEFAULT '',
`info` text,
`lyrics` text,
`picture` varchar(255) NOT NULL DEFAULT '',
`count_played` mediumint(9) NOT NULL DEFAULT '0',
`count_requested` mediumint(9) NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`),
UNIQUE KEY `filename` (`filename`),
KEY `date_played` (`date_played`),
KEY `date_artist_played` (`date_artist_played`),
KEY `date_album_played` (`date_album_played`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=347 ;
Now basically on every song i can show the data making the call to history list. but i need to use the historylist id its pulling. to then connect to the artistlist id so it pulls the lyrics field
hope that helps more
Seems like your join condition is incorrect.
ON historylist.ID = artistlist.ID
If this to be work both table have to have 1-1 relationship. Looking at your table structure i think correct condition would be
ON historylist.artist = artistlist.artist

mysql query times out after certain periodof inactivity - query cache issue i think

using latest mysql server,
after some period of inactivity my website sqls times out (only some not all)
these queries are not newly written existing queries.
Testing results
when execute a simple sql like (select count(*) from products) this works fine all the time.
when execute below sql
SELECT products.pid
FROM
products INNER JOIN
catalog ON products.cid=catalog.cid
WHERE
products.is_visible = 'Yes' AND (
products.inventory_control = 'No' OR
products.stock > 0 OR
products.inventory_rule = 'OutOfStock' OR (
products.inventory_control = 'AttrRuleInc' AND
products.stock >= 0
)
) AND products.is_home = 'Yes'
GROUP BY products.pid
it times out ( Note it will not timeout all the time, this happens after 1 hour or 2 hour of inactivity)
The very first execution takes 30+ seconds and it times out and after that the above executing SQL 2 to 3 times the 4th time onwards it executes fast in 3 to 5 seconds
after 1 or 2 hour inactivity this pattern repeats.
I did not do any changes in settings.
i have 2 sites on this server.
1st server has 20,000 rows of in database ( this one works fine ) 2nd site has 150,000 rows in the databse ( this one is having this issue)
So this is something "query time out"
i do not think this is something on SQL settings, if it is then i should see this behavior on both sites
**** here is the table structure for which the issue with timeout / taking 40 seconds
#this structure has 2 additional keys we created
# KEY `product_id` (`product_id`),
# KEY `product_no` (`product_no`)
# this one is having issues
--
-- Table structure for table `products` on lpbatt database server
--
DROP TABLE IF EXISTS `products`;
SET #saved_cs_client = ##character_set_client;
SET character_set_client = utf8;
CREATE TABLE `products` (
`pid` int(10) unsigned NOT NULL auto_increment,
`cid` int(10) unsigned NOT NULL default '0',
`manufacturer_id` int(10) unsigned NOT NULL default '0',
`is_visible` enum('Yes','No') NOT NULL default 'Yes',
`is_hotdeal` enum('Yes','No') NOT NULL default 'No',
`is_home` enum('Yes','No') NOT NULL default 'No',
`is_taxable` enum('Yes','No') NOT NULL default 'Yes',
`is_dollar_days` enum('Yes','No') NOT NULL default 'No',
`is_google_co` enum('Yes','No') NOT NULL default 'Yes',
`is_doba` enum('Yes','No') NOT NULL default 'No',
`is_locked` enum('Yes','No') NOT NULL default 'No',
`inventory_control` enum('Yes','AttrRuleExc','AttrRuleInc','No') NOT NULL default 'No',
`inventory_rule` enum('Hide','OutOfStock') NOT NULL default 'Hide',
`stock` int(10) NOT NULL default '0',
`stock_warning` int(10) NOT NULL default '0',
`weight` decimal(10,2) unsigned NOT NULL default '0.00',
`free_shipping` enum('Yes','No') NOT NULL default 'No',
`digital_product` enum('Yes','No') NOT NULL default 'No',
`digital_product_file` varchar(255) NOT NULL default '',
`cost` decimal(20,5) unsigned NOT NULL default '0.00000',
`price` decimal(20,5) unsigned NOT NULL default '0.00000',
`price2` decimal(20,5) unsigned NOT NULL default '0.00000',
`price_level_1` decimal(20,5) unsigned NOT NULL default '0.00000',
`price_level_2` decimal(20,5) unsigned NOT NULL default '0.00000',
`price_level_3` decimal(20,5) unsigned NOT NULL default '0.00000',
`shipping_price` decimal(20,5) unsigned NOT NULL default '0.00000',
`tax_class_id` int(10) unsigned NOT NULL default '0',
`tax_rate` decimal(20,5) NOT NULL default '-1.00000',
`call_for_price` enum('Yes','No') NOT NULL default 'No',
`priority` int(11) NOT NULL default '0',
`attributes_count` int(11) NOT NULL default '0',
`min_order` int(10) NOT NULL default '1',
`max_order` int(10) unsigned NOT NULL default '0',
`added` datetime NOT NULL default '0000-00-00 00:00:00',
`products_location_id` int(10) unsigned NOT NULL default '0',
`url_hash` varchar(32) NOT NULL default '',
`url_default` varchar(128) NOT NULL default '',
`url_custom` varchar(128) NOT NULL default '',
`product_id` int(64) NOT NULL default '0',
`product_sku` varchar(64) NOT NULL default '',
`product_upc` varchar(64) NOT NULL default '',
`case_pack` int(11) NOT NULL default '-1',
`inter_pack` int(11) NOT NULL default '-1',
`gift_quantity` int(10) unsigned NOT NULL default '0',
`dimension_width` decimal(10,2) NOT NULL default '0.00',
`dimension_length` decimal(10,2) NOT NULL default '0.00',
`dimension_height` decimal(10,2) NOT NULL default '0.00',
`image_location` enum('Local','Web') NOT NULL default 'Local',
`image_url` varchar(255) NOT NULL default '',
`image_alt_text` varchar(255) NOT NULL default '',
`tmp_manufacturer` varchar(30) default NULL,
`tmp_family` varchar(30) default NULL,
`tmp_series` varchar(30) default NULL,
`tmp_model` varchar(30) default NULL,
`tmp_ptype` varchar(30) default NULL,
`product_no` varchar(40) default NULL,
`part_no` varchar(300) default NULL,
`spec_1` varchar(7) default NULL,
`spec_2` varchar(7) default NULL,
`spec_3` varchar(7) default NULL,
`spec_4` varchar(40) default NULL,
`title` varchar(255) NOT NULL default '',
`meta_keywords` text NOT NULL,
`meta_title` text NOT NULL,
`meta_description` text NOT NULL,
`overview` text,
`description` text,
`zoom_option` enum('global','none','zoom','magnify','magicthumb','imagelayover') NOT NULL default 'global',
PRIMARY KEY (`pid`),
KEY `cid` (`cid`),
KEY `is_visible` (`is_visible`),
KEY `url_hash` (`url_hash`),
KEY `product_id` (`product_id`),
KEY `product_no` (`product_no`)
) ENGINE=MyISAM AUTO_INCREMENT=1630746530 DEFAULT CHARSET=utf8;
SET character_set_client = #saved_cs_client;
below is the table structure which is running on another server but working fine
#see the products table structure and catalog table structure
#this is fine on this server
# --------------------------------------------------------
# Host: laptopnbparts.com
# Database: laptopnbpartscom
# Server version: 5.0.77
# Server OS: redhat-linux-gnu
# HeidiSQL version: 5.0.0.3222
# Date/time: 2010-06-25 18:13:33
# --------------------------------------------------------
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!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' */;
# Dumping structure for table laptopnbpartscom.catalog
CREATE TABLE IF NOT EXISTS `catalog` (
`cid` int(10) unsigned NOT NULL auto_increment,
`parent` int(10) unsigned NOT NULL default '0',
`level` int(10) unsigned NOT NULL default '0',
`priority` smallint(5) unsigned NOT NULL default '5',
`is_visible` enum('Yes','No') NOT NULL default 'Yes',
`list_subcats` enum('Yes','No') NOT NULL default 'No',
`url_hash` varchar(32) NOT NULL default '',
`url_default` varchar(128) NOT NULL default '',
`url_custom` varchar(128) NOT NULL default '',
`key_name` varchar(255) NOT NULL default '',
`meta_keywords` text,
`meta_title` text,
`meta_description` text,
`category_header` varchar(255) NOT NULL default '',
`name` varchar(255) NOT NULL default '',
`description` text,
`description_bottom` text,
`category_path` text,
PRIMARY KEY (`cid`),
KEY `parent` (`parent`),
KEY `level` (`level`),
KEY `priority` (`priority`),
KEY `url_hash` (`url_hash`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
# Data exporting was unselected.
# Dumping structure for table laptopnbpartscom.products
CREATE TABLE IF NOT EXISTS `products` (
`pid` int(10) unsigned NOT NULL auto_increment,
`cid` int(10) unsigned NOT NULL default '0',
`manufacturer_id` int(10) unsigned NOT NULL default '0',
`is_visible` enum('Yes','No') NOT NULL default 'Yes',
`is_hotdeal` enum('Yes','No') NOT NULL default 'No',
`is_home` enum('Yes','No') NOT NULL default 'No',
`is_taxable` enum('Yes','No') NOT NULL default 'Yes',
`is_dollar_days` enum('Yes','No') NOT NULL default 'No',
`is_google_co` enum('Yes','No') NOT NULL default 'Yes',
`is_doba` enum('Yes','No') NOT NULL default 'No',
`is_locked` enum('Yes','No') NOT NULL default 'No',
`inventory_control` enum('Yes','AttrRuleExc','AttrRuleInc','No') NOT NULL default 'No',
`inventory_rule` enum('Hide','OutOfStock') NOT NULL default 'Hide',
`stock` int(10) NOT NULL default '0',
`stock_warning` int(10) NOT NULL default '0',
`weight` decimal(10,2) unsigned NOT NULL default '0.00',
`free_shipping` enum('Yes','No') NOT NULL default 'No',
`digital_product` enum('Yes','No') NOT NULL default 'No',
`digital_product_file` varchar(255) NOT NULL default '',
`cost` decimal(20,5) unsigned NOT NULL default '0.00000',
`price` decimal(20,5) unsigned NOT NULL default '0.00000',
`price2` decimal(20,5) unsigned NOT NULL default '0.00000',
`price_level_1` decimal(20,5) unsigned NOT NULL default '0.00000',
`price_level_2` decimal(20,5) unsigned NOT NULL default '0.00000',
`price_level_3` decimal(20,5) unsigned NOT NULL default '0.00000',
`shipping_price` decimal(20,5) unsigned NOT NULL default '0.00000',
`tax_class_id` int(10) unsigned NOT NULL default '0',
`tax_rate` decimal(20,5) NOT NULL default '-1.00000',
`call_for_price` enum('Yes','No') NOT NULL default 'No',
`priority` int(11) NOT NULL default '0',
`attributes_count` int(11) NOT NULL default '0',
`min_order` int(10) NOT NULL default '1',
`max_order` int(10) unsigned NOT NULL default '0',
`added` datetime NOT NULL default '0000-00-00 00:00:00',
`products_location_id` int(10) unsigned NOT NULL default '0',
`url_hash` varchar(32) NOT NULL default '',
`url_default` varchar(128) NOT NULL default '',
`url_custom` varchar(128) NOT NULL default '',
`product_id` varchar(64) NOT NULL default '',
`product_sku` varchar(64) NOT NULL default '',
`product_upc` varchar(64) NOT NULL default '',
`case_pack` int(11) NOT NULL default '-1',
`inter_pack` int(11) NOT NULL default '-1',
`gift_quantity` int(10) unsigned NOT NULL default '0',
`dimension_width` decimal(10,2) NOT NULL default '0.00',
`dimension_length` decimal(10,2) NOT NULL default '0.00',
`dimension_height` decimal(10,2) NOT NULL default '0.00',
`image_location` enum('Local','Web') NOT NULL default 'Local',
`image_url` varchar(255) NOT NULL default '',
`image_alt_text` varchar(255) NOT NULL default '',
`tmp_manufacturer` varchar(30) default NULL,
`tmp_series` varchar(30) default NULL,
`tmp_model` varchar(30) default NULL,
`tmp_ptype` varchar(30) default NULL,
`product_no` varchar(60) default NULL,
`part_no` varchar(60) default NULL,
`watt_volt_amp` varchar(100) default NULL,
`title` varchar(255) NOT NULL default '',
`meta_keywords` text NOT NULL,
`meta_title` text NOT NULL,
`meta_description` text NOT NULL,
`overview` text,
`description` text,
`zoom_option` enum('global','none','zoom','magnify','magicthumb','imagelayover') NOT NULL default 'global',
PRIMARY KEY (`pid`),
KEY `cid` (`cid`),
KEY `is_visible` (`is_visible`),
KEY `url_hash` (`url_hash`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
# Data exporting was unselected.
/*!40101 SET SQL_MODE=#OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=#OLD_FOREIGN_KEY_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
Try using CASE WHEN instead of the multiple OR statements in the WHERE clause and evaluate on the client side.
OR is a well-known performance killer as MySQL cannot usually apply INDEXes and must check every single statement in order to filter out rows.