I have this query that often shows me "error code 2013. lost connection to mysql query" whenever I run it:
DROP TABLE IF EXISTS elogbook_get_boardid;
CREATE TABLE elogbook_get_boardid AS
(SELECT DISTINCT `LOTID`,
`Board_ID`,
`Serial_Number`,
coalesce(CASE
WHEN A.`Serial_Number` = B.`board_sn` THEN 'In Use'
ELSE A.`status`
END, '') AS `Status`,
coalesce(B.`LOT_LOCATION`, '') AS `chamber`,
coalesce(B.`created_date`, '') AS `Start Date`,
coalesce(B.`BINOUT_DUE_DATE`, '') AS `Est End`
FROM hardware_tracking_msa.HAST_Detail A
LEFT JOIN
(SELECT X.*,
Y.`BINOUT_DUE_DATE`,
Y.`LOT_LOCATION`
FROM skynet_msa.lots_to_hast_boards X
LEFT JOIN skynet_msa.labs_inventory Y ON X.`lotid` = Y.`LOTID`) B ON A.`Serial_Number` = B.`board_sn`
WHERE `LOTID` IS NOT NULL);
I would like to know what makes it take longer than 30 seconds to run and how to improve the query. Any help is appreciated thanks!
Output for hardware_tracking_msa.HAST_Detail:
Index, Board_Number, SIG_Number, Board_ID, Serial_Number, Design_ID, Package, Sockets, Socket_Number, Status, Notes, Deleted_By, Inserted_Date, Inserted_By, Updated_Date, Updated_By, Deleted_Date
'1', '2759', '594-11269', '2759-001', '605637/001', 'J4Q2', 'WFBGA, PIN COUNT: 168/529,PACKAGE SIZE: 12x12', '40', '530-10670 SINGLE BIAS (ESPEC)CANNOT USE FOR J80C/J4Q2', '', '', '', '2022-05-17 14:00:00', 'NWANGA', '2022-05-18 10:15:41', 'tmingyao', '2022-05-17 14:57:33'
'2', '2759', '594-11269', '2759-002', '605637/008', 'J4Q2', 'WFBGA, PIN COUNT: 168/529,PACKAGE SIZE: 12x12', '40', '530-10670 SINGLE BIAS (ESPEC)CANNOT USE FOR J80C/J4Q2', NULL, '', '', '2022-05-17 14:00:00', 'NWANGA', '2022-05-17 14:57:33', '', '2022-05-17 14:57:33'
'3', '2759', '594-11269', '2759-003', '608061/001', 'J4Q2', 'WFBGA, PIN COUNT: 168/529,PACKAGE SIZE: 12x12', '40', '530-10670 SINGLE BIAS (ESPEC)CANNOT USE FOR J80C/J4Q2', NULL, '', '', '2022-05-17 14:00:00', 'NWANGA', '2022-05-17 14:57:33', '', '2022-05-17 14:57:33'
Output for skynet_msa.lots_to_hast_boards:
\begin{table}[]
\begin{tabular}{lll}
lotid, & board\_sn, & created\_date \\
'CVZ2JL2.11', & '1790247/003', & '2022-07-20 '14:26:04 \\
'CV4YJL2.11', & '1317876/002', & '2022-07-20 14:26:04 \\
'CVRMHL2.11', & '1790241/014', & '2022-07-20 14:26:04
\end{tabular}
\end{table}
Output for skynet_msa.labs_inventory:
LOTID, LOCATION, ENV_TEST_INTERVAL, EST_DURATION_TIME, ENV_STRESS_VOLTAGE, ENV_STRESS_VOLT_2, ENV_STRESS_VOLT_3, PRODUCT_FAMILY, PRODUCT_TECHNOLOGY, DESIGN_ID, QA_WORK_REQUEST_NO, QA_PROCESS_TYPE, QA_PROCESS_NAME, QA_BURN_EXPERIMENT, QA_CONTACT, QA_PROCESS_LOT_NO, FABRICATION_FACILITY, ASSEMBLY_FACILITY, ELEC_TEST_FLOW, CONFIGURATION_WIDTH, NUMBER_OF_DIE_IN_PKG, CURRENT_QTY, LOT_LOCATION, LEAD_COUNT, PACKAGE_TYPE, PACKAGE_LENGTH, PACKAGE_WIDTH, PACKAGE_HEIGHT, SOAK_LEVEL, BAKE_TEMPERATURE, DRB_TEMPERATURE, ACTUAL_CURE_TIME, REFLOW_PROFILE, PINOUT_VERSION, DISPATCH_DUE_DATE, BINOUT_DUE_DATE, ROW_CREATED, ROW_MODIFIED, LOCATION_DATE, LOCATION_WW, MODULE_LOT, BURN_LOT, MONITOR_IGNORE, TICKER, PRIORITY, ASM_LOT_NUMBER, MARK_FORMAT, LOCATION_TAT, RPM_WW, QA_EVENT_ID, TC_WEIGHT, AUTOMOTIVE_LOT, CUSTOMER_OPTION, PKG_RECEIVE_DATE, CUSTOMER_GROUP, SAMPLE_PULLED_DATE, QA_SPECIAL_FLOW, QA_BLOCKS, PROBE_CUSTOM_TESTED, QA_PROGRAM_REV, NAND_FLOW_TYPE, NUM_FLASH_CE_PINS, RETICLE_WAVE_ID, MAJOR_PROBE_PROG_REV, MAJOR_TEST_PROG_REV, CYCLING_TYPE, QA_TARGET_CYCLE, LAST_TEST_INTERVAL, CYCLING_TEMPERATURE, ENV_STRESS_DURATION, FIRST_TEST_INTERVAL, DRB_TARGET_INTERVAL, LTDR_TEMPERATURE, RD_STRESS_TYPE
'1623941.001', 'TEMP CYCLE K INV', '25', '12.50', '0.000', '0.000', '0.000', 'MCP', 'ALL IN ONE MCP', 'UM181', '', 'PRODUCTION SCREEN', 'TEMP CYCLE K', '', '', '', 'MIXED', 'ASSEMBLY-MSA', '', '', '8', '2439', 'S01-AR-ASRSIN', '254/432', 'TFBGA', '13.000', '11.500', '1.100', '', '0', '0', '0', '', 'JEDEC', '1970-01-01 00:00:00', NULL, '2022-06-05 18:35:12', '2022-06-06 00:00:16', '2022-06-05 18:35:00', '202223', '0', '0', '0', '0', '4', '1623941.001', '', '1.57', '', 'QA 13', '0', '', '', '1970-01-01 00:00:00', '', '1970-01-01 00:00:00', '', '', 'MOBILE C', '', '', '4', '', '', '', '', '', '', '', '25', '', '', '', ''
'BC4WSXZ.31', 'THERMAL WARPAGE', '0', '0.00', '0.000', '0.000', '0.000', 'MCP', 'MASSFLASH/LPDDR4', 'J86L', '', 'PRODUCTION SCREEN', 'THERMAL WARPAGE', '', '', '', 'MIXED', 'PTI P3', '', '', '2', '26', '', '194/1026', 'UFBGA', '9.000', '12.500', '0.545', '', '0', '0', '0', '', 'AVALON', '1970-01-01 00:00:00', NULL, '2022-07-19 11:00:17', '2022-07-20 13:30:15', '2022-07-19 11:26:45', '202229', '0', '0', '0', '0', '4', 'PT22900.25', 'AVALON', '0.28', '', 'QA 32', '0', '', '', '1970-01-01 00:00:00', '', '2022-07-19 10:58:00', '', '', '', '', '', '1', '', '', '29', '', '', '', '', '', '', '', '', ''
'BC6VVLZ.31', 'TEMP CYCLE K INV', '25', '12.50', '0.000', '0.000', '0.000', 'MCP', 'MASSFLASH/CONTROLLER', 'J39E', '', 'PRODUCTION SCREEN', 'TEMP CYCLE K', '', '', '', 'FAB 10', 'ASSEMBLY-MSA', '', 'X4-X8', '4', '320', 'S01-REL-LAB-IN', '153/196', 'VFBGA', '13.000', '11.500', '1.000', '', '0', '0', '0', '', 'JEDEC', '1970-01-01 00:00:00', NULL, '2022-07-10 14:35:16', '2022-07-11 07:15:19', '2022-07-10 14:31:49', '202228', '0', '0', '0', '0', '4', 'BF3HFCQ.5X', '', '419.25', '', 'QA 45', '0', 'YES', 'AUTOMOTIVE', '1970-01-01 00:00:00', '', '1970-01-01 00:00:00', '', '', 'NAND AUTO', '', '', '4', 'WAVE007', '22', '', '', '', '', '', '25', '', '', '', ''
show create table hardware_tracking_msa.HAST_Detail:
CREATE TABLE `HAST_Detail` (
`Index` int NOT NULL AUTO_INCREMENT,
`Board_Number` varchar(250) DEFAULT \'\',
`SIG_Number` varchar(250) DEFAULT \'\',
`Board_ID` varchar(250) DEFAULT \'\',
`Serial_Number` varchar(250) DEFAULT \'\',
`Design_ID` varchar(150) DEFAULT \'\',
`Package` varchar(250) DEFAULT \'\',
`Sockets` int DEFAULT \'0\',
`Socket_Number` varchar(250) DEFAULT \'\',
`Status` varchar(45) DEFAULT NULL,
`Notes` varchar(1000) DEFAULT \'\',
`Deleted_By` varchar(20) DEFAULT \'\',
`Inserted_Date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`Inserted_By` varchar(20) NOT NULL DEFAULT \'\',
`Updated_Date` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`Updated_By` varchar(20) DEFAULT \'\',
`Deleted_Date` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`Index`)
) ENGINE=InnoDB AUTO_INCREMENT=1459 DEFAULT CHARSET=utf8'
show create table skynet_msa.lots_to_hast_boards:
CREATE TABLE `lots_to_hast_boards` (
`lotid` varchar(45) NOT NULL DEFAULT \'\',
`board_sn` varchar(45) NOT NULL DEFAULT \'\',
`created_date` datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`lotid`,`board_sn`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1'
show create table skynet_msa.labs_inventory:
CREATE TABLE `labs_inventory` (
`LOTID` varchar(12) NOT NULL,
`LOCATION` varchar(48) NOT NULL,
`ENV_TEST_INTERVAL` int DEFAULT \'0\',
`EST_DURATION_TIME` decimal(8,2) DEFAULT \'0.00\',
`ENV_STRESS_VOLTAGE` decimal(6,3) DEFAULT NULL,
`ENV_STRESS_VOLT_2` decimal(6,3) DEFAULT NULL,
`ENV_STRESS_VOLT_3` decimal(6,3) DEFAULT NULL,
`PRODUCT_FAMILY` varchar(45) DEFAULT NULL,
`PRODUCT_TECHNOLOGY` varchar(45) DEFAULT NULL,
`DESIGN_ID` varchar(6) DEFAULT NULL,
`QA_WORK_REQUEST_NO` varchar(100) DEFAULT NULL,
`QA_PROCESS_TYPE` varchar(45) DEFAULT NULL,
`QA_PROCESS_NAME` varchar(64) DEFAULT NULL,
`QA_BURN_EXPERIMENT` varchar(45) DEFAULT NULL,
`QA_CONTACT` varchar(45) DEFAULT NULL,
`QA_PROCESS_LOT_NO` varchar(12) DEFAULT NULL,
`FABRICATION_FACILITY` varchar(45) DEFAULT NULL,
`ASSEMBLY_FACILITY` varchar(45) DEFAULT NULL,
`ELEC_TEST_FLOW` varchar(45) DEFAULT NULL,
`CONFIGURATION_WIDTH` varchar(8) DEFAULT NULL,
`NUMBER_OF_DIE_IN_PKG` int DEFAULT NULL,
`CURRENT_QTY` int DEFAULT NULL,
`LOT_LOCATION` varchar(45) DEFAULT NULL,
`LEAD_COUNT` varchar(45) DEFAULT \'\',
`PACKAGE_TYPE` varchar(45) DEFAULT \'\',
`PACKAGE_LENGTH` decimal(6,3) DEFAULT \'0.000\',
`PACKAGE_WIDTH` decimal(6,3) DEFAULT \'0.000\',
`PACKAGE_HEIGHT` decimal(6,3) DEFAULT \'0.000\',
`SOAK_LEVEL` varchar(45) DEFAULT NULL,
`BAKE_TEMPERATURE` varchar(30) DEFAULT NULL,
`DRB_TEMPERATURE` varchar(30) DEFAULT NULL,
`ACTUAL_CURE_TIME` int DEFAULT NULL,
`REFLOW_PROFILE` varchar(45) DEFAULT NULL,
`PINOUT_VERSION` varchar(45) DEFAULT NULL,
`DISPATCH_DUE_DATE` datetime DEFAULT NULL,
`BINOUT_DUE_DATE` datetime DEFAULT NULL,
`ROW_CREATED` datetime NOT NULL,
`ROW_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`LOCATION_DATE` timestamp NOT NULL DEFAULT \'1970-01-01 12:00:00\',
`LOCATION_WW` varchar(10) DEFAULT NULL,
`MODULE_LOT` int NOT NULL DEFAULT \'0\',
`BURN_LOT` int DEFAULT \'0\',
`MONITOR_IGNORE` int NOT NULL DEFAULT \'0\',
`TICKER` int NOT NULL DEFAULT \'0\',
`PRIORITY` varchar(4) DEFAULT NULL,
`ASM_LOT_NUMBER` varchar(45) DEFAULT NULL,
`MARK_FORMAT` varchar(45) DEFAULT NULL,
`LOCATION_TAT` double DEFAULT \'0\',
`RPM_WW` varchar(10) DEFAULT NULL,
`QA_EVENT_ID` varchar(15) DEFAULT NULL,
`TC_WEIGHT` double DEFAULT \'0\',
`AUTOMOTIVE_LOT` varchar(45) DEFAULT NULL,
`CUSTOMER_OPTION` varchar(45) DEFAULT NULL,
`PKG_RECEIVE_DATE` datetime DEFAULT NULL,
`CUSTOMER_GROUP` varchar(45) DEFAULT NULL,
`SAMPLE_PULLED_DATE` datetime DEFAULT NULL,
`QA_SPECIAL_FLOW` varchar(45) DEFAULT NULL,
`QA_BLOCKS` varchar(45) DEFAULT NULL,
`PROBE_CUSTOM_TESTED` varchar(45) DEFAULT NULL,
`QA_PROGRAM_REV` varchar(45) DEFAULT NULL,
`NAND_FLOW_TYPE` varchar(45) DEFAULT NULL,
`NUM_FLASH_CE_PINS` varchar(45) DEFAULT NULL,
`RETICLE_WAVE_ID` varchar(45) DEFAULT NULL,
`MAJOR_PROBE_PROG_REV` varchar(45) DEFAULT NULL,
`MAJOR_TEST_PROG_REV` varchar(45) DEFAULT NULL,
`CYCLING_TYPE` varchar(45) DEFAULT NULL,
`QA_TARGET_CYCLE` varchar(45) DEFAULT NULL,
`LAST_TEST_INTERVAL` varchar(45) DEFAULT NULL,
`CYCLING_TEMPERATURE` varchar(45) DEFAULT NULL,
`ENV_STRESS_DURATION` varchar(45) DEFAULT NULL,
`FIRST_TEST_INTERVAL` varchar(45) DEFAULT NULL,
`DRB_TARGET_INTERVAL` varchar(45) DEFAULT NULL,
`LTDR_TEMPERATURE` varchar(45) DEFAULT NULL,
`RD_STRESS_TYPE` varchar(45) DEFAULT NULL,
PRIMARY KEY (`LOTID`),
KEY `design_id` (`DESIGN_ID`),
KEY `lot_location` (`LOT_LOCATION`),
KEY `burn` (`DESIGN_ID`,`QA_BURN_EXPERIMENT`),
KEY `locations` (`LOT_LOCATION`,`LOCATION`),
KEY `all_index` (`LOCATION`,`LOT_LOCATION`,`DISPATCH_DUE_DATE`,`PRODUCT_FAMILY`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
COMMENT=\'table to store MAM data for msa labs skynet\''
EXPLAIN QUERY:
id, select_type, table, partitions, type, possible_keys, key, key_len, ref, rows, filtered, Extra
'1', 'SIMPLE', 'X', NULL, 'ALL', 'PRIMARY', NULL, NULL, NULL, '55', '90.00', 'Using where'
'1', 'SIMPLE', 'Y', NULL, 'eq_ref', 'PRIMARY', 'PRIMARY', '14', 'skynet_msa.X.lotid', '1', '100.00', 'Using where'
'1', 'SIMPLE', 'A', NULL, 'ALL', NULL, NULL, NULL, NULL, '1458', '10.00', 'Using where; Using join buffer (hash join)'
Change from MyISAM to InnoDB. (It may not matter for this query.)
Tentative index to add:
A: INDEX(Serial_Number, status)
LEFT is not needed:
LEFT JOIN ( ... ) B ON ... WHERE b.id IS NOT NULL
-->
JOIN ( ... ) B ON ...
At that point, it may be reasonable to get rid of the nested LEFT JOIN, and simply have a single level A, X, Y joined together.
The EXPLAIN shows that at least some of those simplifications were automatically figured out by the Optimizer.
A.Serial_Number = B.`board_sn
I see "utf8" and "latin1". If any query JOINs on a VARCHAR between different Character Sets, (ore Collations), an otherwise-suitable index will not be used. If that is a problem, I suggest you use ALTER .. CONVERT TO .. to change latin1 to utf8.
I see columns called "DURATION" and "INTERVAL" being declared VARCHAR. This can cause trouble if you ever do numeric operations on such columns. (I understand things like "BOARD_SN" are not really numbers.)
Related
I have a big SQL query that selects totals by month and groups by merchants. It works well and displays everything I need. The problem is I also need the merchant with no transaction to show in the list. So fare, the merchant gets a total only if he did at least one transaction. We need to calculate the monthly fees even if a merchant made 0 transaction.
My current SQL looks like this.
SELECT
t.id,
m.name AS merchant_name,
DATE_FORMAT(t.transaction_date, '%Y-%m') AS DATE,
SUM(t.amount) AS total_sales,
COUNT(t.id) AS total_transactions
FROM
merchants m
LEFT JOIN transactions t ON
t.merchant_id = m.id
WHERE
t.transaction_date LIKE '2020-08%'
GROUP BY
DATE_FORMAT(t.transaction_date, '%Y-%m'),
t.merchant_id
ORDER BY
t.transaction_date
DESC
So I was thinking about this ... and thought maybe I could do a second query for merchants with out transactions and merge both results together... but so fare I got no luck at all. My query returns no error but says no results. If there's a way of doing this in only one query it would be a lot better thought. Here's my second query in case.
SELECT
m.id,
m.name AS merchant_name,
COUNT(t.id) as transaction_count,
SUM(0) AS total_sales,
COUNT(t.id) AS total_transactions,
FROM
merchants m
LEFT JOIN transactions t ON
t.merchant_id = m.id
WHERE
t.transaction_date like '2020-08%'
HAVING transaction_count = 0
My transaction table looks like this
CREATE TABLE `transactions` (
`id` int(10) UNSIGNED NOT NULL,
`transaction_type` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`account_number` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`routing_number` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`fund_amt` decimal(15,2) DEFAULT NULL,
`batch_reference` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`batch_type` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`customer_batch_reference` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`customer_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`merchant_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`external_mid` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`store_number` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`chain` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`batch_amt` decimal(15,2) DEFAULT NULL,
`amount` decimal(15,2) DEFAULT NULL,
`surchg_amount` decimal(15,2) DEFAULT NULL,
`convnce_amt` decimal(15,2) DEFAULT NULL,
`card_type` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`charge_type` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`card_plan` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`card_no` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`chk_num` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`transaction_date` datetime DEFAULT NULL,
`settlement_date` datetime DEFAULT NULL,
`authorization_code` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`chargback_control_no` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`roc_text` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`trn_aci` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`card_scheme_ref` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`trn_ref_num` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`settlement_method` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`currency_code` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`cb_acq_ref` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`chgbk_rsn_code` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`chgbk_rsn_desc` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`mer_ref` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`purch` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`cust_cod` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`trn_arn` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`term` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`ent_num` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`charge_type_description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`payment_reference` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`payment_date` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`i_plus_visa` decimal(9,2) DEFAULT 0.00,
`pi_visa` decimal(9,2) DEFAULT 0.00,
`i_plus_Vdebit` decimal(9,2) DEFAULT 0.00,
`pi_Vdebit` decimal(9,2) DEFAULT 0.00,
`i_plus_mc` decimal(9,2) DEFAULT 0.00,
`pi_mc` decimal(9,2) DEFAULT 0.00,
`i_plus_amex` decimal(9,2) DEFAULT 0.00,
`pi_amex` decimal(9,2) DEFAULT 0.00,
`i_plus_discover` decimal(9,2) DEFAULT 0.00,
`pi_discover` decimal(9,2) DEFAULT 0.00,
`i_plus_union` decimal(9,2) DEFAULT 0.00,
`pi_union` decimal(9,2) DEFAULT 0.00,
`i_plus_MCdebit` decimal(9,2) DEFAULT 0.00,
`pi_MCdebit` decimal(9,2) DEFAULT 0.00,
`pi_debit` decimal(9,2) DEFAULT 0.00,
`pi_flash` decimal(9,2) DEFAULT 0.00,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`customer_id` int(10) UNSIGNED DEFAULT NULL,
`merchant_id` int(10) UNSIGNED DEFAULT NULL,
`batch_id` int(10) UNSIGNED DEFAULT NULL,
`converge_res` text COLLATE utf8mb4_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
// 5 Transactions
INSERT INTO `transactions` (`id`, `transaction_type`, `account_number`, `routing_number`, `fund_amt`, `batch_reference`, `batch_type`, `customer_batch_reference`, `customer_name`, `merchant_name`, `external_mid`, `store_number`, `chain`, `batch_amt`, `amount`, `surchg_amount`, `convnce_amt`, `card_type`, `charge_type`, `card_plan`, `card_no`, `chk_num`, `transaction_date`, `settlement_date`, `authorization_code`, `chargback_control_no`, `roc_text`, `trn_aci`, `card_scheme_ref`, `trn_ref_num`, `settlement_method`, `currency_code`, `cb_acq_ref`, `chgbk_rsn_code`, `chgbk_rsn_desc`, `mer_ref`, `purch`, `cust_cod`, `trn_arn`, `term`, `ent_num`, `charge_type_description`, `payment_reference`, `payment_date`, `i_plus_visa`, `pi_visa`, `i_plus_Vdebit`, `pi_Vdebit`, `i_plus_mc`, `pi_mc`, `i_plus_amex`, `pi_amex`, `i_plus_discover`, `pi_discover`, `i_plus_union`, `pi_union`, `i_plus_MCdebit`, `pi_MCdebit`, `pi_debit`, `pi_flash`, `created_at`, `updated_at`, `customer_id`, `merchant_id`, `batch_id`, `converge_res`) VALUES
(1, '1', '***123', '00000124162', '370.90', '17290458149', 'D', '00000000043', 'name 1', NULL, '8033407712', '', '00000', '370.90', '65.00', '0.00', '0.00', '032', '02465', 'M/C', '556923******2454', '', '2019-10-16 00:00:00', '2019-10-16 00:00:00', '613342', NULL, '', '', 'MCFPHH5FS', '17290458152', 'ACH', 'CAD', NULL, '', '', '00065069751', NULL, '', '55259569290172904581529', NULL, '48627', 'MC CHIP DOM COMMERCIAL', '929000000127220', '2019-08-17 00:00:00', '0.03', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '2020-09-21 01:58:00', '2020-09-23 00:36:54', NULL, 1, 1, NULL),
(2, '1', '***123', '00000124162', '370.90', '17290458149', 'D', '00000000043', 'name 1', NULL, '8033407712', '', '00000', '370.90', '114.00', '0.00', '0.00', '049', '01810', 'INTC', '472409******9229', '', '2019-10-16 00:00:00', '2019-10-16 00:00:00', '224694', NULL, '', '', '', '17290458155', 'ACH', 'CAD', NULL, '', '', '00065069754', NULL, '', '0000000000017290458155X', NULL, '48627', 'PIN DEBIT RETAIL BASE', '929000000127220', '2019-10-17 00:00:00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.09', '0.00', '2020-09-21 01:58:00', '2020-09-23 00:31:58', NULL, 1, 1, NULL),
(3, '1', '***124', '00000124162', '323.35', '73290783323', 'D', '00000000033', 'name 2', NULL, '8033407712', '', '00000', '323.35', '103.50', '0.00', '0.00', '032', '02465', 'M/C', '556960******7782', '', '2019-10-16 00:00:00', '2019-10-16 00:00:00', '066015', NULL, '', '', 'MCFPFPTVH', '73290783327', 'ACH', 'CAD', NULL, '', '', '00064918465', NULL, '', '55259569290732907833274', NULL, '48627', 'MC CHIP DOM COMMERCIAL', '929000000127221', '2019-08-17 00:00:00', '0.05', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '2020-09-21 01:58:00', '2020-09-23 00:36:54', NULL, 2, 2, NULL),
(4, '1', '***124', '00000124162', '323.35', '73290783323', 'D', '00000000033', 'name 2', NULL, '8033407712', '', '00000', '323.35', '88.55', '0.00', '0.00', '026', '02465', 'M/C', '558700******1934', '', '2019-10-16 00:00:00', '2019-10-16 00:00:00', '034367', NULL, '', '', 'MCBQL61VH', '73290783328', 'ACH', 'CAD', NULL, '', '', '00064918466', NULL, '', '55259569290732907833282', NULL, '48627', 'MC CHIP DOM COMMERCIAL', '929000000127221', '2019-08-17 00:00:00', '0.04', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '2020-09-21 01:58:00', '2020-09-23 00:36:54', NULL, 2, 2, NULL),
(5, '1', '***125', '00000124162', '323.35', '73290783323', 'D', '00000000033', 'name 3', NULL, '8033407712', '', '00000', '323.35', '71.30', '0.00', '0.00', '026', '02465', 'M/C', '552822******0618', '', '2019-10-16 00:00:00', '2019-10-16 00:00:00', '006983', NULL, '', '', 'MCO00Q4RH', '73290783324', 'ACH', 'CAD', NULL, '', '', '00064918462', NULL, '', '55259569290732907833241', NULL, '48627', 'MC CHIP DOM COMMERCIAL', '929000000127221', '2019-08-17 00:00:00', '0.04', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '2020-09-21 01:58:00', '2020-09-23 00:36:54', NULL, 3, 2, NULL);
In the above we have 5 transaction owned by 3 merchants. Let say I have 5 merchants. How can I end up with 5 results where 2 have empty totals
Move the condition from the WHERE-clause into the LEFT JOIN so that the condition will not exclude the merchants with no transactions. The t.id in SELECT in your first query does not really make sense, maybe you meant m.id?
SELECT
m.id,
m.name AS merchant_name,
DATE_FORMAT(t.transaction_date, '%Y-%m') AS DATE,
ifnull(SUM(t.amount),0) AS total_sales,
COUNT(t.id) AS total_transactions
FROM
merchants m
LEFT JOIN transactions t ON
t.merchant_id = m.id and t.transaction_date LIKE '2020-08%'
GROUP BY
m.id,
m.name,
DATE_FORMAT(t.transaction_date, '%Y-%m')
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!
I try to populate mysql database column values to json values of items without success.
Database structure:
CREATE TABLE IF NOT EXISTS `ejkb4_k2_items` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`code` varchar(11) NOT NULL,
`title` varchar(255) NOT NULL,
`alias` varchar(255) DEFAULT NULL,
`catid` int(11) NOT NULL,
`published` smallint(6) NOT NULL DEFAULT '0',
`introtext` mediumtext,
`fulltext` mediumtext,
`video` text,
`gallery` varchar(255) DEFAULT NULL,
`extra_fields` text CHARACTER SET utf8 COLLATE utf8_unicode_ci,
`extra_fields_search` text NOT NULL,
`created` datetime NOT NULL,
`created_by` int(11) NOT NULL DEFAULT '0',
`created_by_alias` varchar(255) NOT NULL,
`checked_out` int(10) unsigned NOT NULL,
`checked_out_time` datetime NOT NULL,
`modified` datetime NOT NULL,
`modified_by` int(11) NOT NULL DEFAULT '0',
`publish_up` datetime NOT NULL,
`publish_down` datetime NOT NULL,
`trash` smallint(6) NOT NULL DEFAULT '0',
`access` int(11) NOT NULL DEFAULT '0',
`ordering` int(11) NOT NULL DEFAULT '0',
`featured` smallint(6) NOT NULL DEFAULT '0',
`featured_ordering` int(11) NOT NULL DEFAULT '0',
`image_caption` text NOT NULL,
`image_credits` varchar(255) NOT NULL,
`video_caption` text NOT NULL,
`video_credits` varchar(255) NOT NULL,
`hits` int(10) unsigned NOT NULL,
`params` text NOT NULL,
`metadesc` text NOT NULL,
`metadata` text NOT NULL,
`metakey` text NOT NULL,
`plugins` varchar(1024) NOT NULL DEFAULT 'k2storeitem_price=1',
`code_search` varchar(11) NOT NULL,
`language` char(7) NOT NULL,
PRIMARY KEY (`id`),
KEY `item` (`published`,`publish_up`,`publish_down`,`trash`,`access`),
KEY `catid` (`catid`),
KEY `created_by` (`created_by`),
KEY `ordering` (`ordering`),
KEY `featured` (`featured`),
KEY `featured_ordering` (`featured_ordering`),
KEY `hits` (`hits`),
KEY `language` (`language`),
FULLTEXT KEY `search` (`title`,`introtext`,`fulltext`,`extra_fields_search`,`image_caption`,`image_credits`,`video_caption`,`video_credits`,`metadesc`,`metakey`),
FULLTEXT KEY `title` (`title`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=992 ;
One item from this database table:
INSERT INTO `ejkb4_k2_items` (`id`, `code`, `title`, `alias`, `catid`, `published`, `introtext`, `fulltext`, `video`, `gallery`, `extra_fields`, `extra_fields_search`, `created`, `created_by`, `created_by_alias`, `checked_out`, `checked_out_time`, `modified`, `modified_by`, `publish_up`, `publish_down`, `trash`, `access`, `ordering`, `featured`, `featured_ordering`, `image_caption`, `image_credits`, `video_caption`, `video_credits`, `hits`, `params`, `metadesc`, `metadata`, `metakey`, `plugins`, `code_search`, `language`) VALUES
(992, '1234567', 'Спирателен вентил ХХХ', 'спирателен-вентил-ххх', 704, 1, '<ul>\r\n<li>материал</li>\r\n<li>още нещо</li>\r\n<li>друго...</li>\r\n<li>и още</li>\r\n</ul>', '', '<iframe width="560" height="315" src="https://www.youtube.com/embed/pMPinbC1VJ4" frameborder="0" allowfullscreen></iframe>', NULL, '[{"id":"1","value":"1\\""},{"id":"9","value":"22311"},{"id":"5","value":""},{"id":"6","value":""},{"id":"7","value":""},{"id":"8","value":""},{"id":"10","value":"\\u041f\\u0440\\u043e\\u0438\\u0437\\u0432\\u043e\\u0434\\u0438\\u0442\\u0435\\u043b \\u0425"}]', '1" 22311 Производител Х ', '2017-05-30 07:27:22', 50, '', 0, '0000-00-00 00:00:00', '2017-06-06 13:20:35', 50, '2017-05-30 07:27:22', '0000-00-00 00:00:00', 0, 1, 2, 0, 0, '', '', '', '', 14, '{"catItemTitle":"","catItemTitleLinked":"","catItemFeaturedNotice":"","catItemAuthor":"","catItemDateCreated":"","catItemRating":"","catItemImage":"","catItemIntroText":"","catItemExtraFields":"","catItemHits":"","catItemCategory":"","catItemTags":"","catItemAttachments":"","catItemAttachmentsCounter":"","catItemVideo":"","catItemVideoWidth":"","catItemVideoHeight":"","catItemAudioWidth":"","catItemAudioHeight":"","catItemVideoAutoPlay":"","catItemImageGallery":"","catItemImageGalleryWidth":"","catItemImageGalleryHeight":"","catItemDateModified":"","catItemReadMore":"","catItemCommentsAnchor":"","catItemK2Plugins":"","itemDateCreated":"","itemTitle":"","itemFeaturedNotice":"","itemAuthor":"","itemFontResizer":"","itemPrintButton":"","itemEmailButton":"","itemSocialButton":"","itemVideoAnchor":"","itemImageGalleryAnchor":"","itemCommentsAnchor":"","itemRating":"","itemImage":"","itemImgSize":"","itemImageMainCaption":"","itemImageMainCredits":"","itemIntroText":"","itemFullText":"","itemExtraFields":"","itemDateModified":"","itemHits":"","itemCategory":"","itemTags":"","itemAttachments":"","itemAttachmentsCounter":"","itemVideo":"","itemVideoWidth":"","itemVideoHeight":"","itemAudioWidth":"","itemAudioHeight":"","itemVideoAutoPlay":"","itemVideoCaption":"","itemVideoCredits":"","itemImageGallery":"","itemImageGalleryWidth":"","itemImageGalleryHeight":"","itemNavigation":"","itemComments":"","itemTwitterButton":"","itemFacebookButton":"","itemGooglePlusOneButton":"","itemAuthorBlock":"","itemAuthorImage":"","itemAuthorDescription":"","itemAuthorURL":"","itemAuthorEmail":"","itemAuthorLatest":"","itemAuthorLatestLimit":"","itemRelated":"","itemRelatedLimit":"","itemRelatedTitle":"","itemRelatedCategory":"","itemRelatedImageSize":"","itemRelatedIntrotext":"","itemRelatedFulltext":"","itemRelatedAuthor":"","itemRelatedMedia":"","itemRelatedImageGallery":"","itemK2Plugins":""}', '', 'robots=\nauthor=', '', '{"k2storeitem_enabled":"1","k2storeitem_sku":"","k2storeitem_price":"","k2storespecial_price":"","k2storeitem_tax":"0","k2storeitem_shipping":"0","k2storeitem_metrics":{"item_length":"0.00000000","item_width":"0.00000000","item_height":"0.00000000","item_length_class_id":"0","item_weight":"0.00000000","item_weight_class_id":"0"},"k2storeitem_cart_text":""}', '', '*');
All values from column code must be populated to column extra_fields - as value of id:9. For example {"id":"9","value":"22311"} must going to: {"id":"9","value":"1234567"} in all database items.
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?
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