#SET GLOBAL myisam_stats_method = nulls_equal; -> does NOT help #CHECK TABLE drdat, mitarbeiter, firma, stadt, fsdaten, fahrt; # does not come back without straigh_join # ft has to come AFTER dstop. EXPLAIN SELECT #STRAIGHT_JOIN f.name AS drdat_firma_name, s.name AS drdat_stadt_name, f.rechnung_vor_tag AS drdat_rechnung_vor_tag, d.firma_id AS drdat_firma_id , d.stadt_id AS drdat_stadt_id , d.mnr_id AS drdat_mnr_id , d.abrechnungstyp AS drdat_abrechnungstyp, d.druckdatum AS drdat_druckdatum_alt , d.fahrten_von AS drdat_fahrten_von_alt, d.fahrten_bis AS drdat_fahrten_bis_alt, IF(fs.drdat_tag IS NULL OR fs.drdat_intervall_einheit='D', IF(fs.drdat_intervall_einheit='M', ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall MONTH), IF(fs.drdat_intervall_einheit='W', ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall*7 DAY), ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall DAY))), IF(fs.drdat_intervall_einheit='M', IF(GREATEST(ADDDATE(d.druckdatum, INTERVAL 10 DAY), IFNULL(d.fahrten_bis,'0000-00-00')) > IF(DAYOFMONTH(ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall MONTH)) IF(DAYOFWEEK(ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall*7 DAY)) IF(DAYOFMONTH(ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall MONTH)) IF(DAYOFWEEK(ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall*7 DAY)) NOW(), 'zukuenftig','zu_starten') AS drdat_status , ADDDATE(d.fahrten_bis, INTERVAL 1 DAY) AS drdat_fahrten_von , IF(fs.drdat_intervall_einheit='M', IF(DAYOFMONTH(IF(fs.drdat_tag IS NULL OR fs.drdat_intervall_einheit='D', IF(fs.drdat_intervall_einheit='M', ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall MONTH), IF(fs.drdat_intervall_einheit='W', ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall*7 DAY), ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall DAY))), IF(fs.drdat_intervall_einheit='M', IF(GREATEST(ADDDATE(d.druckdatum, INTERVAL 10 DAY), IFNULL(d.fahrten_bis,'0000-00-00')) > IF(DAYOFMONTH(ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall MONTH)) IF(DAYOFWEEK(ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall*7 DAY))= f.rechnung_vor_tag, SUBDATE(CONCAT(DATE_FORMAT(IF(fs.drdat_tag IS NULL OR fs.drdat_intervall_einheit='D', IF(fs.drdat_intervall_einheit='M', ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall MONTH), IF(fs.drdat_intervall_einheit='W', ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall*7 DAY), ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall DAY))), IF(fs.drdat_intervall_einheit='M', IF(GREATEST(ADDDATE(d.druckdatum, INTERVAL 10 DAY), IFNULL(d.fahrten_bis,'0000-00-00')) > IF(DAYOFMONTH(ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall MONTH)) IF(DAYOFWEEK(ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall*7 DAY)) IF(DAYOFMONTH(ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall MONTH)) IF(DAYOFWEEK(ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall*7 DAY)) IF(DAYOFMONTH(ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall MONTH)) IF(DAYOFWEEK(ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall*7 DAY)) IF(DAYOFMONTH(ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall MONTH)) IF(DAYOFWEEK(ADDDATE(d.druckdatum, INTERVAL fs.drdat_intervall*7 DAY))