Re: Reproducing incorrect order with order by in a subquery

2023-06-15 Thread Karsten Hilbert
Am Thu, Jun 15, 2023 at 12:58:55AM +0300 schrieb Ruslan Zakirov: e.g. > https://mariadb.com/kb/en/why-is-order-by-in-a-from-subquery-ignored/ ... > My goal was to find a small dataset that demonstrates this ordering > mismatch. I attempted to think it through whether it is even *possible* to f

Re: Reproducing incorrect order with order by in a subquery

2023-06-14 Thread Ruslan Zakirov
On Wed, Jun 14, 2023 at 3:50 PM Karsten Hilbert wrote: > IOW neither is help to be expected on this list nor can any > testing (on PG) help with anything to be expected on MySQL ? > Don't expect any help on mysql part. As to the question: since the outer query does not have an > ORDER BY it can

Re: Reproducing incorrect order with order by in a subquery

2023-06-14 Thread Karsten Hilbert
Am Wed, Jun 14, 2023 at 01:03:06PM +0300 schrieb Ruslan Zakirov: > > This is a too complex query to build a test on. Tried simpler scenarios > > and failed. > > > > First of all I want to apologize. We work with multiple RDBMS systems. This > particular user is using mysql. ... > Anyway, yesterday

Re: Reproducing incorrect order with order by in a subquery

2023-06-14 Thread Ron
On 6/14/23 05:03, Ruslan Zakirov wrote: [snip] Anyway, yesterday I tried my simplified case on Pg latest, Pg 11 and on mysql latest. Had no luck. Either my test case is too simple or I can not find the correct distribution of data between two tables. This is when you need a prod copy... -- Bo

Re: Reproducing incorrect order with order by in a subquery

2023-06-14 Thread Ruslan Zakirov
On Tue, Jun 13, 2023 at 8:55 PM Ruslan Zakirov wrote: > On Tue, Jun 13, 2023 at 6:06 PM Tom Lane wrote: > >> Ruslan Zakirov writes: >> > I know how to fix the problem and I know that ORDER BY should be in the >> > outermost select. >> >> > However, I want to write a test case that shows that th

Re: Reproducing incorrect order with order by in a subquery

2023-06-13 Thread David G. Johnston
On Tue, Jun 13, 2023 at 10:55 AM Ruslan Zakirov wrote: > Thanks for replying. Maybe I'm just wrong in my assumption. A user reports > incorrect order in the following query: > > SELECT main.*, COUNT(main.id) OVER() AS search_builder_count_all FROM ( > SELECT DISTINCT main.* FROM Tickets main >

Re: Reproducing incorrect order with order by in a subquery

2023-06-13 Thread Ruslan Zakirov
On Tue, Jun 13, 2023 at 6:06 PM Tom Lane wrote: > Ruslan Zakirov writes: > > I know how to fix the problem and I know that ORDER BY should be in the > > outermost select. > > > However, I want to write a test case that shows that the old code is > wrong, > > but can not create > > minimal set of

Re: Reproducing incorrect order with order by in a subquery

2023-06-13 Thread Tom Lane
Ruslan Zakirov writes: > I know how to fix the problem and I know that ORDER BY should be in the > outermost select. > However, I want to write a test case that shows that the old code is wrong, > but can not create > minimal set of tables to reproduce it. With this I'm looking for help. The ORD

Re: Reproducing incorrect order with order by in a subquery

2023-06-13 Thread Ruslan Zakirov
On Tue, Jun 13, 2023 at 1:26 PM Thomas Kellerer wrote: > Ruslan Zakirov schrieb am 13.06.2023 um 09:49: > > For example I have a query: > > > > SELECT main.*, count(*) OVER () FROM (SELECT DISTINCT ... ORDER BY X) > > main; > > > > So the `ORDER BY` clause ended up in a subquery. Most of the time

Re: Reproducing incorrect order with order by in a subquery

2023-06-13 Thread Thomas Kellerer
Ruslan Zakirov schrieb am 13.06.2023 um 09:49: > For example I have a query: > > SELECT main.*, count(*) OVER () FROM (SELECT DISTINCT ... ORDER BY X) > main; > > So the `ORDER BY` clause ended up in a subquery. Most of the time > ordering works until it doesn't. > > Can you help me create a set of

Reproducing incorrect order with order by in a subquery

2023-06-13 Thread Ruslan Zakirov
Hello, For example I have a query: SELECT main.*, count(*) OVER () FROM (SELECT DISTINCT ... ORDER BY X) main; So the `ORDER BY` clause ended up in a subquery. Most of the time ordering works until it doesn't. Can you help me create a set of test tables with some data to reproduce this problem