0

The query was reduced to the least number of parts that still produce the error. Just for explanation purposes.

SELECT
        s.Saison,
        t.Saison,
        IF(s.Saison = t.Saison,'gleich','unterschiedlich')
FROM tbl_spielplan s
LEFT JOIN
          (SELECT
                        Kino_Id,
                        Saison,
                        (SUM(Besucher_Zahlend+Besucher_Frei)/COUNT(*)) AS Summe_T
                FROM
                        tbl_spielplan
                WHERE
                        Film_gezeigt='1'
                GROUP BY
                        Kino_Id,
                        Saison) AS t
ON s.Kino_Id = t.Kino_Id
WHERE
        Film_Id   = '3109'
AND     s.Kino_Id < 300
AND     s.Saison = t.Saison; 

Gives no Matches found. If I omit the s.Saison = t.Saison i get

s.Saison t.Saison if clause match
2019 WiSe 2019 WiSe gleich
2019 WiSe 2019 SoSe unterschiedlich
2019 WiSe 2018 WiSe unterschiedlich

if i match only on s.Saison = t.Saison the join works but it will fail if i add s.Kino_Id = t.Kino_Id in the where clause. Now for the Really weird part, if I add AND BINARY s.Saison = t.Saison; in the on or where clause the problem stops. Also not all datasets produce this error. I Tested it in multiple instances of mariadb 10.3 and 10.5. This behavior is new, half a year ago the query worked every time. in Mariadb 10.1 the query works without fail.

I Already found a workaround, I am more interested in the why, as in my Understanding, this should not be happening.

Hauke
  • 1
  • DId you look at the upgrade notes that almost all software provide to let us all know about code breaking changes in updates? See [the upgrade notes](https://mariadb.com/kb/en/upgrading/) – RiggsFolly Jun 28 '21 at 09:18
  • I Checked the upgrade notes, however please note i did not upgrade the database to a different Maria DB version. Only Security Fixes and Updates were installed on MariaDB 10.5. None of the Patchnotes mentioned anything that could explain this behavior. 10.3 was just used to see if the bug was only added to 10.5. – Hauke Jun 28 '21 at 10:08

1 Answers1

0

you are using left outer join from in wrong way. try this

SELECT
        s.Saison,
        t.Saison,
        IF(s.Saison = t.Saison,'gleich','unterschiedlich')
FROM tbl_spielplan s
LEFT JOIN
          (SELECT
                        Kino_Id,
                        Saison,
                        (SUM(Besucher_Zahlend+Besucher_Frei)/COUNT(*)) AS Summe_T
                FROM
                        tbl_spielplan
                WHERE
                        Film_gezeigt='1'
                GROUP BY
                        Kino_Id,
                        Saison) AS t
ON s.Kino_Id = t.Kino_Id and s.Saison = t.Saison
WHERE
        Film_Id   = '3109'
AND     s.Kino_Id < 300 ;

The table with outer join should not be used in where condition.

Amit Verma
  • 2,450
  • 2
  • 8
  • 21
  • As I Said it does not matter if the condition is in the on or where condition, this one produces the same bug. – Hauke Jun 28 '21 at 09:21
  • ON s.Saison = t.Saison and s.Kino_Id = t.Kino_Id will produce a different bug as now the Saison match will work but the Kino_Id match will fail. – Hauke Jun 28 '21 at 09:24