Problems with exists: subselect

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems with exists: subselect

jtuchel
Hi,

I am not sure if I am encountering a Glorp bug or if my code is incorrect. Glorp creates a subselect referencing a table as s1t2 which is not used anywhere in the query.

Here's my Smalltalk code:

    query := SimpleQuery read: KontolinoPurchase.
    query where: [:k |
        (k package id = 1)
            AND:
                (k dateOfPurchase between: (Date today subtractDays: 2) and: (Date today subtractDays: 1))
            AND: (k dateWelcomeMail = nil)].
    query where: [:k |
        k exists: [Query read: User where: [:b | b company = k company AND: (b isActive)]]].

And the resulting SQL code:

SELECT t1.id, "long list of columns prefixed with t1"
 FROM DB2INST1.PURCHASE t1
 WHERE  EXISTS (SELECT s1t1.id, "long list of attributes prefixed with s1t1"
 FROM DB2INST1.USER s1t1
 WHERE ((s1t1.company_id = s1t2.id) AND s1t1.active))

And this is what DB2 shouts at me:

[SQLSTATE=42S22 - [IBM][CLI Driver][DB2/LINUXX8664] SQL0206N  "S1T2.ID" is not valid in this context.  SQLSTATE=42703 [Native Error=-206]]

I tend to absolutely agree with DB2 here. But what am I doing wrong in my subselect? There is a 1:n relationship between Purchase and User, and the purpose of the query is to find package purchases that were bought yesterday and the day before and which have not received a welcome mail yet. At least one of the users in that company have to be activated (otherwise we do not want to send a mail message to the company).


Why does Glorp use a s1t2 prefix here?
Any ideas are welcome

Joachim



--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/43abbfcc-13f1-41f4-91b0-5056d601f564%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

RE: Problems with exists: subselect

Wallen, David

Hi Jocheim,

 

Sorry I don’t have time to look at this in detail, but you might want to examine the glorp clauses and the SQL produced in GlorpDBTests. For example,

                GlorpAnySatisfyTest>>testAnySatisfyTwiceNested

There is at least some overlap with your description.

Hth,

Dave

 

Dave Wallen 
Software Engineer
 

https://no-cache.hubspot.com/cta/default/431576/c36613c8-e7ed-43e4-96aa-21da1a227630.png

blank
office:
513-612-2003
website: www.cincomsmalltalk.com
email: [hidden email]
 

 
 
 https://no-cache.hubspot.com/cta/default/431576/0488e96d-1f19-4f15-9229-6366998fd492.png   https://no-cache.hubspot.com/cta/default/431576/98535c75-36a7-4ad2-886f-59aed10b7d2d.png   https://no-cache.hubspot.com/cta/default/431576/1b963ee4-96da-4a8d-92b5-dc1c5570e9ad.png   https://no-cache.hubspot.com/cta/default/431576/dc3c920a-1832-4080-afb7-2e78ad67d354.png   https://no-cache.hubspot.com/cta/default/431576/df552d48-897f-4524-babf-2e9a83340091.png

 

--- CONFIDENTIALITY STATEMENT ---

This e-mail transmission contains information that is intended to be privileged and confidential. It is intended only for the addressee named above. If you receive this e-mail in error, please do not read, copy or disseminate it in any manner. If you are not the intended recipient, any disclosure, copying, distribution or use of the contents of this information is prohibited, please reply to the message immediately by informing the sender that the message was misdirected. After replying, please erase it from your computer system. Your assistance in correcting this error is appreciated.

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of jtuchel
Sent: Tuesday, May 14, 2019 3:06 AM
To: glorp-group
Subject: Problems with exists: subselect

 

Hi,

 

I am not sure if I am encountering a Glorp bug or if my code is incorrect. Glorp creates a subselect referencing a table as s1t2 which is not used anywhere in the query.

 

Here's my Smalltalk code:

 

    query := SimpleQuery read: KontolinoPurchase.
    query where: [:k |
        (k package id = 1)
            AND:
                (k dateOfPurchase between: (Date today subtractDays: 2) and: (Date today subtractDays: 1))
            AND: (k dateWelcomeMail = nil)].
    query where: [:k |
        k exists: [Query read: User where: [:b | b company = k company AND: (b isActive)]]].

 

And the resulting SQL code:

 

SELECT t1.id, "long list of columns prefixed with t1"
 FROM DB2INST1.PURCHASE t1
 WHERE  EXISTS (SELECT s1t1.id, "long list of attributes prefixed with s1t1"
 FROM DB2INST1.USER s1t1
 WHERE ((s1t1.company_id = s1t2.id) AND s1t1.active))

 

And this is what DB2 shouts at me:

 

[SQLSTATE=42S22 - [IBM][CLI Driver][DB2/LINUXX8664] SQL0206N  "S1T2.ID" is not valid in this context.  SQLSTATE=42703 [Native Error=-206]]

 

I tend to absolutely agree with DB2 here. But what am I doing wrong in my subselect? There is a 1:n relationship between Purchase and User, and the purpose of the query is to find package purchases that were bought yesterday and the day before and which have not received a welcome mail yet. At least one of the users in that company have to be activated (otherwise we do not want to send a mail message to the company).

 

 

Why does Glorp use a s1t2 prefix here?

Any ideas are welcome

 

Joachim

 

 

 

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/43abbfcc-13f1-41f4-91b0-5056d601f564%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/BY5PR13MB30319AD8B1D6730BF004CA52C9090%40BY5PR13MB3031.namprd13.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

RE: Problems with exists: subselect

Wallen, David

Sorry, Joachim, I’m the world’s absolute worst speller!

Dave

 

From: Wallen, David
Sent: Tuesday, May 14, 2019 8:42 PM
To: [hidden email]
Subject: RE: Problems with exists: subselect

 

Hi Jocheim,

 

Sorry I don’t have time to look at this in detail, but you might want to examine the glorp clauses and the SQL produced in GlorpDBTests. For example,

                GlorpAnySatisfyTest>>testAnySatisfyTwiceNested

There is at least some overlap with your description.

Hth,

Dave

 

Dave Wallen 
Software Engineer
 

https://no-cache.hubspot.com/cta/default/431576/c36613c8-e7ed-43e4-96aa-21da1a227630.png

blank
office:
513-612-2003
website: www.cincomsmalltalk.com
email: [hidden email]
 

 
 
 https://no-cache.hubspot.com/cta/default/431576/0488e96d-1f19-4f15-9229-6366998fd492.png   https://no-cache.hubspot.com/cta/default/431576/98535c75-36a7-4ad2-886f-59aed10b7d2d.png   https://no-cache.hubspot.com/cta/default/431576/1b963ee4-96da-4a8d-92b5-dc1c5570e9ad.png   https://no-cache.hubspot.com/cta/default/431576/dc3c920a-1832-4080-afb7-2e78ad67d354.png   https://no-cache.hubspot.com/cta/default/431576/df552d48-897f-4524-babf-2e9a83340091.png

 

--- CONFIDENTIALITY STATEMENT ---

This e-mail transmission contains information that is intended to be privileged and confidential. It is intended only for the addressee named above. If you receive this e-mail in error, please do not read, copy or disseminate it in any manner. If you are not the intended recipient, any disclosure, copying, distribution or use of the contents of this information is prohibited, please reply to the message immediately by informing the sender that the message was misdirected. After replying, please erase it from your computer system. Your assistance in correcting this error is appreciated.

 

 

From: [hidden email] [[hidden email]] On Behalf Of jtuchel
Sent: Tuesday, May 14, 2019 3:06 AM
To: glorp-group
Subject: Problems with exists: subselect

 

Hi,

 

I am not sure if I am encountering a Glorp bug or if my code is incorrect. Glorp creates a subselect referencing a table as s1t2 which is not used anywhere in the query.

 

Here's my Smalltalk code:

 

    query := SimpleQuery read: KontolinoPurchase.
    query where: [:k |
        (k package id = 1)
            AND:
                (k dateOfPurchase between: (Date today subtractDays: 2) and: (Date today subtractDays: 1))
            AND: (k dateWelcomeMail = nil)].
    query where: [:k |
        k exists: [Query read: User where: [:b | b company = k company AND: (b isActive)]]].

 

And the resulting SQL code:

 

SELECT t1.id, "long list of columns prefixed with t1"
 FROM DB2INST1.PURCHASE t1
 WHERE  EXISTS (SELECT s1t1.id, "long list of attributes prefixed with s1t1"
 FROM DB2INST1.USER s1t1
 WHERE ((s1t1.company_id = s1t2.id) AND s1t1.active))

 

And this is what DB2 shouts at me:

 

[SQLSTATE=42S22 - [IBM][CLI Driver][DB2/LINUXX8664] SQL0206N  "S1T2.ID" is not valid in this context.  SQLSTATE=42703 [Native Error=-206]]

 

I tend to absolutely agree with DB2 here. But what am I doing wrong in my subselect? There is a 1:n relationship between Purchase and User, and the purpose of the query is to find package purchases that were bought yesterday and the day before and which have not received a welcome mail yet. At least one of the users in that company have to be activated (otherwise we do not want to send a mail message to the company).

 

 

Why does Glorp use a s1t2 prefix here?

Any ideas are welcome

 

Joachim

 

 

 

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/43abbfcc-13f1-41f4-91b0-5056d601f564%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/BY5PR13MB30310B1CA8130CDB0F50D25AC9090%40BY5PR13MB3031.namprd13.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with exists: subselect

Thomas Brodt
In reply to this post by jtuchel

Hi Joachim,

maybe it is a side effect of twice setting the where-block for the query? At least I cannot see anything wrong, and we also have exists-queries written that way that work.

I assume you simplified the code for testing the exists only and modified the where: assignment. Or did you want to add the exists with AND: instead of where:?

Thomas

Am 14.05.2019 um 12:05 schrieb jtuchel:
Hi,

I am not sure if I am encountering a Glorp bug or if my code is incorrect. Glorp creates a subselect referencing a table as s1t2 which is not used anywhere in the query.

Here's my Smalltalk code:

    query := SimpleQuery read: KontolinoPurchase.
    query where: [:k |
        (k package id = 1)
            AND:
                (k dateOfPurchase between: (Date today subtractDays: 2) and: (Date today subtractDays: 1))
            AND: (k dateWelcomeMail = nil)].
    query where: [:k |
        k exists: [Query read: User where: [:b | b company = k company AND: (b isActive)]]].

And the resulting SQL code:

SELECT t1.id, "long list of columns prefixed with t1"
 FROM DB2INST1.PURCHASE t1
 WHERE  EXISTS (SELECT s1t1.id, "long list of attributes prefixed with s1t1"
 FROM DB2INST1.USER s1t1
 WHERE ((s1t1.company_id = s1t2.id) AND s1t1.active))

And this is what DB2 shouts at me:

[SQLSTATE=42S22 - [IBM][CLI Driver][DB2/LINUXX8664] SQL0206N  "S1T2.ID" is not valid in this context.  SQLSTATE=42703 [Native Error=-206]]

I tend to absolutely agree with DB2 here. But what am I doing wrong in my subselect? There is a 1:n relationship between Purchase and User, and the purpose of the query is to find package purchases that were bought yesterday and the day before and which have not received a welcome mail yet. At least one of the users in that company have to be activated (otherwise we do not want to send a mail message to the company).


Why does Glorp use a s1t2 prefix here?
Any ideas are welcome

Joachim



--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/43abbfcc-13f1-41f4-91b0-5056d601f564%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/3c440e6a-1285-86e7-55cf-ddc77cf4e0cf%40porabo.ch.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with exists: subselect

jtuchel
Hi Thomas,

thanks for taking such a sharp look at my code. Indeed, I had a "second" where: in my code. *facepalm*
So I replaced the second where: with AND:

Unfortunately, it doesn't solve the problem, however. Instead I now have two ;-)

The first one is that the prefix s1t2 ist still there. The second is that I get another Error which says there is no decscrptor for User. I seem to remember this is a bug which has been discussed here and needs some extra care with #asGlorpExpressionOn: and such. I need to investigate further.

I also tried expressing this with only a single block (you are of course right, the code I wrote here is a simple extract from the original) and still I get the s1t2 problem:

    query := SimpleQuery read: KontolinoPurchase.
    query where: [:k |
        (k package id = 1)
            AND:
                (k dateOfPurchase between: (Date today subtractDays: 2) and: (Date today subtractDays: 1))
            AND: (k dateWelcomeMail = nil)
            AND:
        (k exists: [Query read: User where: [:b | b company = k company AND: (b isActive)]])].


Joachim

Am 15.05.19 um 10:58 schrieb Thomas Brodt:

Hi Joachim,

maybe it is a side effect of twice setting the where-block for the query? At least I cannot see anything wrong, and we also have exists-queries written that way that work.

I assume you simplified the code for testing the exists only and modified the where: assignment. Or did you want to add the exists with AND: instead of where:?

Thomas

Am 14.05.2019 um 12:05 schrieb jtuchel:
Hi,

I am not sure if I am encountering a Glorp bug or if my code is incorrect. Glorp creates a subselect referencing a table as s1t2 which is not used anywhere in the query.

Here's my Smalltalk code:

    query := SimpleQuery read: KontolinoPurchase.
    query where: [:k |
        (k package id = 1)
            AND:
                (k dateOfPurchase between: (Date today subtractDays: 2) and: (Date today subtractDays: 1))
            AND: (k dateWelcomeMail = nil)].
    query where: [:k |
        k exists: [Query read: User where: [:b | b company = k company AND: (b isActive)]]].

And the resulting SQL code:

SELECT t1.id, "long list of columns prefixed with t1"
 FROM DB2INST1.PURCHASE t1
 WHERE  EXISTS (SELECT s1t1.id, "long list of attributes prefixed with s1t1"
 FROM DB2INST1.USER s1t1
 WHERE ((s1t1.company_id = s1t2.id) AND s1t1.active))

And this is what DB2 shouts at me:

[SQLSTATE=42S22 - [IBM][CLI Driver][DB2/LINUXX8664] SQL0206N  "S1T2.ID" is not valid in this context.  SQLSTATE=42703 [Native Error=-206]]

I tend to absolutely agree with DB2 here. But what am I doing wrong in my subselect? There is a 1:n relationship between Purchase and User, and the purpose of the query is to find package purchases that were bought yesterday and the day before and which have not received a welcome mail yet. At least one of the users in that company have to be activated (otherwise we do not want to send a mail message to the company).


Why does Glorp use a s1t2 prefix here?
Any ideas are welcome

Joachim



--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/43abbfcc-13f1-41f4-91b0-5056d601f564%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


-- 
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          [hidden email]
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1


--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/a1510648-d301-0ce1-86f8-f985cca2fe7c%40objektfabrik.de.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with exists: subselect

Alan Knight
I'm guessing here, but the problem you refer to is probably that when building complex queries, a block can either get built without a proper base expression, or you can get it built with two different base expressions. So if there are two different ones, you could get the problem that they don't know about the joined tables that each other has created, so you can get an orphan table like s1t2. And if a base expression doesn't have a descriptor associated with it then you could get the second error. The usual fix is to explicitly do an asGlorpExpression on the baseExpression of the other part.

On Wed, May 15, 2019, 02:41 [hidden email] <[hidden email]> wrote:
Hi Thomas,

thanks for taking such a sharp look at my code. Indeed, I had a "second" where: in my code. *facepalm*
So I replaced the second where: with AND:

Unfortunately, it doesn't solve the problem, however. Instead I now have two ;-)

The first one is that the prefix s1t2 ist still there. The second is that I get another Error which says there is no decscrptor for User. I seem to remember this is a bug which has been discussed here and needs some extra care with #asGlorpExpressionOn: and such. I need to investigate further.

I also tried expressing this with only a single block (you are of course right, the code I wrote here is a simple extract from the original) and still I get the s1t2 problem:

    query := SimpleQuery read: KontolinoPurchase.
    query where: [:k |
        (k package id = 1)
            AND:
                (k dateOfPurchase between: (Date today subtractDays: 2) and: (Date today subtractDays: 1))
            AND: (k dateWelcomeMail = nil)
            AND:
        (k exists: [Query read: User where: [:b | b company = k company AND: (b isActive)]])].


Joachim

Am 15.05.19 um 10:58 schrieb Thomas Brodt:

Hi Joachim,

maybe it is a side effect of twice setting the where-block for the query? At least I cannot see anything wrong, and we also have exists-queries written that way that work.

I assume you simplified the code for testing the exists only and modified the where: assignment. Or did you want to add the exists with AND: instead of where:?

Thomas

Am 14.05.2019 um 12:05 schrieb jtuchel:
Hi,

I am not sure if I am encountering a Glorp bug or if my code is incorrect. Glorp creates a subselect referencing a table as s1t2 which is not used anywhere in the query.

Here's my Smalltalk code:

    query := SimpleQuery read: KontolinoPurchase.
    query where: [:k |
        (k package id = 1)
            AND:
                (k dateOfPurchase between: (Date today subtractDays: 2) and: (Date today subtractDays: 1))
            AND: (k dateWelcomeMail = nil)].
    query where: [:k |
        k exists: [Query read: User where: [:b | b company = k company AND: (b isActive)]]].

And the resulting SQL code:

SELECT t1.id, "long list of columns prefixed with t1"
 FROM DB2INST1.PURCHASE t1
 WHERE  EXISTS (SELECT s1t1.id, "long list of attributes prefixed with s1t1"
 FROM DB2INST1.USER s1t1
 WHERE ((s1t1.company_id = s1t2.id) AND s1t1.active))

And this is what DB2 shouts at me:

[SQLSTATE=42S22 - [IBM][CLI Driver][DB2/LINUXX8664] SQL0206N  "S1T2.ID" is not valid in this context.  SQLSTATE=42703 [Native Error=-206]]

I tend to absolutely agree with DB2 here. But what am I doing wrong in my subselect? There is a 1:n relationship between Purchase and User, and the purpose of the query is to find package purchases that were bought yesterday and the day before and which have not received a welcome mail yet. At least one of the users in that company have to be activated (otherwise we do not want to send a mail message to the company).


Why does Glorp use a s1t2 prefix here?
Any ideas are welcome

Joachim



--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/43abbfcc-13f1-41f4-91b0-5056d601f564%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


-- 
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          [hidden email]
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1


--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/a1510648-d301-0ce1-86f8-f985cca2fe7c%40objektfabrik.de.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/CAGWHZ9-GmFDLAJ1uGCg3mMvMSjjCux9RXCD%2BC9LCAOo7pW0VGg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with exists: subselect

jtuchel
Alan,

this sounds reasonable. I just don't understand it ;-)

Let me try to rephrase:

I'd ask the query after it has been created with #where: for its #baseExpression and then send asGlorpExpressionOn: baseExpressionFromFirstPart to the Block that's handed over to AND: ?


Joachim



Am 15.05.19 um 15:26 schrieb Alan Knight:
I'm guessing here, but the problem you refer to is probably that when building complex queries, a block can either get built without a proper base expression, or you can get it built with two different base expressions. So if there are two different ones, you could get the problem that they don't know about the joined tables that each other has created, so you can get an orphan table like s1t2. And if a base expression doesn't have a descriptor associated with it then you could get the second error. The usual fix is to explicitly do an asGlorpExpression on the baseExpression of the other part.

On Wed, May 15, 2019, 02:41 [hidden email] <[hidden email]> wrote:
Hi Thomas,

thanks for taking such a sharp look at my code. Indeed, I had a "second" where: in my code. *facepalm*
So I replaced the second where: with AND:

Unfortunately, it doesn't solve the problem, however. Instead I now have two ;-)

The first one is that the prefix s1t2 ist still there. The second is that I get another Error which says there is no decscrptor for User. I seem to remember this is a bug which has been discussed here and needs some extra care with #asGlorpExpressionOn: and such. I need to investigate further.

I also tried expressing this with only a single block (you are of course right, the code I wrote here is a simple extract from the original) and still I get the s1t2 problem:

    query := SimpleQuery read: KontolinoPurchase.
    query where: [:k |
        (k package id = 1)
            AND:
                (k dateOfPurchase between: (Date today subtractDays: 2) and: (Date today subtractDays: 1))
            AND: (k dateWelcomeMail = nil)
            AND:
        (k exists: [Query read: User where: [:b | b company = k company AND: (b isActive)]])].


Joachim

Am 15.05.19 um 10:58 schrieb Thomas Brodt:

Hi Joachim,

maybe it is a side effect of twice setting the where-block for the query? At least I cannot see anything wrong, and we also have exists-queries written that way that work.

I assume you simplified the code for testing the exists only and modified the where: assignment. Or did you want to add the exists with AND: instead of where:?

Thomas

Am 14.05.2019 um 12:05 schrieb jtuchel:
Hi,

I am not sure if I am encountering a Glorp bug or if my code is incorrect. Glorp creates a subselect referencing a table as s1t2 which is not used anywhere in the query.

Here's my Smalltalk code:

    query := SimpleQuery read: KontolinoPurchase.
    query where: [:k |
        (k package id = 1)
            AND:
                (k dateOfPurchase between: (Date today subtractDays: 2) and: (Date today subtractDays: 1))
            AND: (k dateWelcomeMail = nil)].
    query where: [:k |
        k exists: [Query read: User where: [:b | b company = k company AND: (b isActive)]]].

And the resulting SQL code:

SELECT t1.id, "long list of columns prefixed with t1"
 FROM DB2INST1.PURCHASE t1
 WHERE  EXISTS (SELECT s1t1.id, "long list of attributes prefixed with s1t1"
 FROM DB2INST1.USER s1t1
 WHERE ((s1t1.company_id = s1t2.id) AND s1t1.active))

And this is what DB2 shouts at me:

[SQLSTATE=42S22 - [IBM][CLI Driver][DB2/LINUXX8664] SQL0206N  "S1T2.ID" is not valid in this context.  SQLSTATE=42703 [Native Error=-206]]

I tend to absolutely agree with DB2 here. But what am I doing wrong in my subselect? There is a 1:n relationship between Purchase and User, and the purpose of the query is to find package purchases that were bought yesterday and the day before and which have not received a welcome mail yet. At least one of the users in that company have to be activated (otherwise we do not want to send a mail message to the company).


Why does Glorp use a s1t2 prefix here?
Any ideas are welcome

Joachim



--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/43abbfcc-13f1-41f4-91b0-5056d601f564%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


-- 
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          [hidden email]
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1


--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/a1510648-d301-0ce1-86f8-f985cca2fe7c%40objektfabrik.de.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "glorp-group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/glorp-group/_HPQ7nYR4_k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/CAGWHZ9-GmFDLAJ1uGCg3mMvMSjjCux9RXCD%2BC9LCAOo7pW0VGg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


-- 
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          [hidden email]
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1


--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/29908544-b8bc-4a11-26f0-b71a25f90695%40objektfabrik.de.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with exists: subselect

Thomas Brodt
In reply to this post by jtuchel

Hi Joachim,

have you tried

  (k exists: (Query read: User where: [:b | b company = k company AND: (b isActive)]))

instead of

  (k exists: [Query read: User where: [:b | b company = k company AND: (b isActive)]])

giving the exists: a query in parentheses instead of a BlockClosure in square brackets?

Thomas


Am 15.05.2019 um 11:41 schrieb [hidden email]:
Hi Thomas,

thanks for taking such a sharp look at my code. Indeed, I had a "second" where: in my code. *facepalm*
So I replaced the second where: with AND:

Unfortunately, it doesn't solve the problem, however. Instead I now have two ;-)

The first one is that the prefix s1t2 ist still there. The second is that I get another Error which says there is no decscrptor for User. I seem to remember this is a bug which has been discussed here and needs some extra care with #asGlorpExpressionOn: and such. I need to investigate further.

I also tried expressing this with only a single block (you are of course right, the code I wrote here is a simple extract from the original) and still I get the s1t2 problem:

    query := SimpleQuery read: KontolinoPurchase.
    query where: [:k |
        (k package id = 1)
            AND:
                (k dateOfPurchase between: (Date today subtractDays: 2) and: (Date today subtractDays: 1))
            AND: (k dateWelcomeMail = nil)
            AND:
        (k exists: [Query read: User where: [:b | b company = k company AND: (b isActive)]])].


Joachim

Am 15.05.19 um 10:58 schrieb Thomas Brodt:

Hi Joachim,

maybe it is a side effect of twice setting the where-block for the query? At least I cannot see anything wrong, and we also have exists-queries written that way that work.

I assume you simplified the code for testing the exists only and modified the where: assignment. Or did you want to add the exists with AND: instead of where:?

Thomas

Am 14.05.2019 um 12:05 schrieb jtuchel:
Hi,

I am not sure if I am encountering a Glorp bug or if my code is incorrect. Glorp creates a subselect referencing a table as s1t2 which is not used anywhere in the query.

Here's my Smalltalk code:

    query := SimpleQuery read: KontolinoPurchase.
    query where: [:k |
        (k package id = 1)
            AND:
                (k dateOfPurchase between: (Date today subtractDays: 2) and: (Date today subtractDays: 1))
            AND: (k dateWelcomeMail = nil)].
    query where: [:k |
        k exists: [Query read: User where: [:b | b company = k company AND: (b isActive)]]].

And the resulting SQL code:

SELECT t1.id, "long list of columns prefixed with t1"
 FROM DB2INST1.PURCHASE t1
 WHERE  EXISTS (SELECT s1t1.id, "long list of attributes prefixed with s1t1"
 FROM DB2INST1.USER s1t1
 WHERE ((s1t1.company_id = s1t2.id) AND s1t1.active))

And this is what DB2 shouts at me:

[SQLSTATE=42S22 - [IBM][CLI Driver][DB2/LINUXX8664] SQL0206N  "S1T2.ID" is not valid in this context.  SQLSTATE=42703 [Native Error=-206]]

I tend to absolutely agree with DB2 here. But what am I doing wrong in my subselect? There is a 1:n relationship between Purchase and User, and the purpose of the query is to find package purchases that were bought yesterday and the day before and which have not received a welcome mail yet. At least one of the users in that company have to be activated (otherwise we do not want to send a mail message to the company).


Why does Glorp use a s1t2 prefix here?
Any ideas are welcome

Joachim



--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/43abbfcc-13f1-41f4-91b0-5056d601f564%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


-- 
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          [hidden email]
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1


--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/c6541c88-cfd6-1830-9fb1-9321a19875ff%40porabo.ch.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with exists: subselect

jtuchel
In reply to this post by Alan Knight

Alan,


I tried this:


    query := SimpleQuery read: KontolinoPaketKauf.
    query where: [:k |
        (k paket id = 1) AND: (k kaufDatum < Date today) AND: (k datumFrischAktiviertMail = nil)].

    "Es muss auch aktivierte benutzer geben, sonst darf das nicht versandt werden"
    bExp := query baseExpression.
    query AND: (
        [:k | k exists: (Query read: Benutzer where: [:b | b mandant = k kunde AND: (b aktiv)])]
            asGlorpExpressionOn: bExp).


But still get the same error....


Jaochim


--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/6e0c6868-6b44-a53a-0ad4-8b713edc5f8b%40objektfabrik.de.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with exists: subselect

Thomas Brodt

We had something like this:

Query
        read: WBPPersonal
        where: [:each |
            | subQuery |
            subQuery := Query
                read: WBPLeistung
                where: [:lei | lei datumVon = Date today AND: [lei personal = each]].
            subQuery retrieve: [:x | 'x'].
            each exists: subQuery].

Maybe reducing the retrieve block to only one column and some constant for each rows helps?

Thomas

Am 15.05.2019 um 16:15 schrieb [hidden email]:

Alan,


I tried this:


    query := SimpleQuery read: KontolinoPaketKauf.
    query where: [:k |
        (k paket id = 1) AND: (k kaufDatum < Date today) AND: (k datumFrischAktiviertMail = nil)].

    "Es muss auch aktivierte benutzer geben, sonst darf das nicht versandt werden"
    bExp := query baseExpression.
    query AND: (
        [:k | k exists: (Query read: Benutzer where: [:b | b mandant = k kunde AND: (b aktiv)])]
            asGlorpExpressionOn: bExp).


But still get the same error....


Jaochim


--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/6e0c6868-6b44-a53a-0ad4-8b713edc5f8b%40objektfabrik.de.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/bc667e31-d216-73aa-2983-a9f9b54f9865%40porabo.ch.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with exists: subselect

Alan Knight
In reply to this post by jtuchel
Yes, exactly. Although now that I think about it I'd expect the and: operation to do that anyway. So there might be something more subtle going on, perhaps with a nested block.

On Wed, May 15, 2019, 07:39 [hidden email] <[hidden email]> wrote:
Alan,

this sounds reasonable. I just don't understand it ;-)

Let me try to rephrase:

I'd ask the query after it has been created with #where: for its #baseExpression and then send asGlorpExpressionOn: baseExpressionFromFirstPart to the Block that's handed over to AND: ?


Joachim



Am 15.05.19 um 15:26 schrieb Alan Knight:
I'm guessing here, but the problem you refer to is probably that when building complex queries, a block can either get built without a proper base expression, or you can get it built with two different base expressions. So if there are two different ones, you could get the problem that they don't know about the joined tables that each other has created, so you can get an orphan table like s1t2. And if a base expression doesn't have a descriptor associated with it then you could get the second error. The usual fix is to explicitly do an asGlorpExpression on the baseExpression of the other part.

On Wed, May 15, 2019, 02:41 [hidden email] <[hidden email]> wrote:
Hi Thomas,

thanks for taking such a sharp look at my code. Indeed, I had a "second" where: in my code. *facepalm*
So I replaced the second where: with AND:

Unfortunately, it doesn't solve the problem, however. Instead I now have two ;-)

The first one is that the prefix s1t2 ist still there. The second is that I get another Error which says there is no decscrptor for User. I seem to remember this is a bug which has been discussed here and needs some extra care with #asGlorpExpressionOn: and such. I need to investigate further.

I also tried expressing this with only a single block (you are of course right, the code I wrote here is a simple extract from the original) and still I get the s1t2 problem:

    query := SimpleQuery read: KontolinoPurchase.
    query where: [:k |
        (k package id = 1)
            AND:
                (k dateOfPurchase between: (Date today subtractDays: 2) and: (Date today subtractDays: 1))
            AND: (k dateWelcomeMail = nil)
            AND:
        (k exists: [Query read: User where: [:b | b company = k company AND: (b isActive)]])].


Joachim

Am 15.05.19 um 10:58 schrieb Thomas Brodt:

Hi Joachim,

maybe it is a side effect of twice setting the where-block for the query? At least I cannot see anything wrong, and we also have exists-queries written that way that work.

I assume you simplified the code for testing the exists only and modified the where: assignment. Or did you want to add the exists with AND: instead of where:?

Thomas

Am 14.05.2019 um 12:05 schrieb jtuchel:
Hi,

I am not sure if I am encountering a Glorp bug or if my code is incorrect. Glorp creates a subselect referencing a table as s1t2 which is not used anywhere in the query.

Here's my Smalltalk code:

    query := SimpleQuery read: KontolinoPurchase.
    query where: [:k |
        (k package id = 1)
            AND:
                (k dateOfPurchase between: (Date today subtractDays: 2) and: (Date today subtractDays: 1))
            AND: (k dateWelcomeMail = nil)].
    query where: [:k |
        k exists: [Query read: User where: [:b | b company = k company AND: (b isActive)]]].

And the resulting SQL code:

SELECT t1.id, "long list of columns prefixed with t1"
 FROM DB2INST1.PURCHASE t1
 WHERE  EXISTS (SELECT s1t1.id, "long list of attributes prefixed with s1t1"
 FROM DB2INST1.USER s1t1
 WHERE ((s1t1.company_id = s1t2.id) AND s1t1.active))

And this is what DB2 shouts at me:

[SQLSTATE=42S22 - [IBM][CLI Driver][DB2/LINUXX8664] SQL0206N  "S1T2.ID" is not valid in this context.  SQLSTATE=42703 [Native Error=-206]]

I tend to absolutely agree with DB2 here. But what am I doing wrong in my subselect? There is a 1:n relationship between Purchase and User, and the purpose of the query is to find package purchases that were bought yesterday and the day before and which have not received a welcome mail yet. At least one of the users in that company have to be activated (otherwise we do not want to send a mail message to the company).


Why does Glorp use a s1t2 prefix here?
Any ideas are welcome

Joachim



--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/43abbfcc-13f1-41f4-91b0-5056d601f564%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


-- 
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          [hidden email]
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1


--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/a1510648-d301-0ce1-86f8-f985cca2fe7c%40objektfabrik.de.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "glorp-group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/glorp-group/_HPQ7nYR4_k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/CAGWHZ9-GmFDLAJ1uGCg3mMvMSjjCux9RXCD%2BC9LCAOo7pW0VGg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


-- 
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          [hidden email]
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1


--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/29908544-b8bc-4a11-26f0-b71a25f90695%40objektfabrik.de.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/CAGWHZ9-PvrBRTFXBAdv%3DW2jp-2cnme-8ym08t5hn%2B0NQ%2B-5yMw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with exists: subselect

Tom Robinson
In reply to this post by Thomas Brodt
In general, reducing the fields that subqueries retrieve to only the ones you need to satisfy their conditional function is likely to simplify the SQL generated and improve performance.

On 5/15/2019 8:26 AM, Thomas Brodt wrote:

We had something like this:

Query
        read: WBPPersonal
        where: [:each |
            | subQuery |
            subQuery := Query
                read: WBPLeistung
                where: [:lei | lei datumVon = Date today AND: [lei personal = each]].
            subQuery retrieve: [:x | 'x'].
            each exists: subQuery].

Maybe reducing the retrieve block to only one column and some constant for each rows helps?

Thomas

Am 15.05.2019 um 16:15 schrieb [hidden email]:

Alan,


I tried this:


    query := SimpleQuery read: KontolinoPaketKauf.
    query where: [:k |
        (k paket id = 1) AND: (k kaufDatum < Date today) AND: (k datumFrischAktiviertMail = nil)].

    "Es muss auch aktivierte benutzer geben, sonst darf das nicht versandt werden"
    bExp := query baseExpression.
    query AND: (
        [:k | k exists: (Query read: Benutzer where: [:b | b mandant = k kunde AND: (b aktiv)])]
            asGlorpExpressionOn: bExp).


But still get the same error....


Jaochim


--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/6e0c6868-6b44-a53a-0ad4-8b713edc5f8b%40objektfabrik.de.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/bc667e31-d216-73aa-2983-a9f9b54f9865%40porabo.ch.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/3019bba9-9b83-3ecf-c418-3bb76b3aeb89%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with exists: subselect

jtuchel
In reply to this post by Thomas Brodt
Thomas,


thanks again for taking time to look at my problem.

Unfortunately, it seems this still doesn't work. I now tried this:

    query := SimpleQuery read: KontolinoPaketKauf.
    query where: [:k | |sub|
        sub := Query read: Benutzer where: [:b | b mandant = k kunde AND: (b aktiv)].
        sub retrieve: [:x| 'hit'].   
        (k paket id = 1)
            AND: (k kaufDatum < Date today)
            AND: (k datumFrischAktiviertMail = nil)
            AND: (k exists: sub)].




and still got this SQl statement:

SELECT t1.id, "long list of all mapped attributes in that table, not relevant here"
 FROM DB2INST1.PAKETKAUF t1
 WHERE (((
   (t1.paket_id = 1)
   AND (t1.DATUM < '2019-05-17'))
   AND (t1.DAT_AKTIVIERT_MAIL IS NULL))
  AND  EXISTS (
   SELECT 'hit' FROM DB2INST1.BENUTZER s1t1
   WHERE ((s1t1.firma_id = s1t2.id)
  AND s1t1.aktiv)))


So the table pefix s1t2 is still occuring in this SQL and leads to an SQL error, the JOIN is not correctly determined. I'm giving up on this. I have also tried a few variations of sending several asGlorpExpressionOn: variants and stuff and never get any useful SQL.

Joachim






Am Mittwoch, 15. Mai 2019 16:26:35 UTC+2 schrieb Thomas Brodt:

We had something like this:

Query
        read: WBPPersonal
        where: [:each |
            | subQuery |
            subQuery := Query
                read: WBPLeistung
                where: [:lei | lei datumVon = Date today AND: [lei personal = each]].
            subQuery retrieve: [:x | 'x'].
            each exists: subQuery].

Maybe reducing the retrieve block to only one column and some constant for each rows helps?

Thomas

Am 15.05.2019 um 16:15 schrieb <a href="javascript:" target="_blank" gdf-obfuscated-mailto="_KjkJAKbAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jtu...@...:

Alan,


I tried this:


    query := SimpleQuery read: KontolinoPaketKauf.
    query where: [:k |
        (k paket id = 1) AND: (k kaufDatum < Date today) AND: (k datumFrischAktiviertMail = nil)].

    "Es muss auch aktivierte benutzer geben, sonst darf das nicht versandt werden"
    bExp := query baseExpression.
    query AND: (
        [:k | k exists: (Query read: Benutzer where: [:b | b mandant = k kunde AND: (b aktiv)])]
            asGlorpExpressionOn: bExp).


But still get the same error....


Jaochim


--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="_KjkJAKbAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">glorp...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="_KjkJAKbAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">glorp...@....
Visit this group at <a href="https://groups.google.com/group/glorp-group" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/glorp-group&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/glorp-group&#39;;return true;">https://groups.google.com/group/glorp-group.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/glorp-group/6e0c6868-6b44-a53a-0ad4-8b713edc5f8b%40objektfabrik.de?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/glorp-group/6e0c6868-6b44-a53a-0ad4-8b713edc5f8b%40objektfabrik.de?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/glorp-group/6e0c6868-6b44-a53a-0ad4-8b713edc5f8b%40objektfabrik.de?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/glorp-group/6e0c6868-6b44-a53a-0ad4-8b713edc5f8b%40objektfabrik.de.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/afa0a154-d575-4a9d-a290-cd6d6c496d04%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with exists: subselect

jtuchel
In reply to this post by Tom Robinson
Yeah, I'm a big fan of good performance, once things work ;-) I admit the SQL in my last attempt using the retrieve: trick makes the SQL much more readable as well. If only it was correct as well...


Am Mittwoch, 15. Mai 2019 19:34:58 UTC+2 schrieb Tom Robinson:
In general, reducing the fields that subqueries retrieve to only the ones you need to satisfy their conditional function is likely to simplify the SQL generated and improve performance.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/f4161294-6caf-455c-aac5-2440ba6eda10%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with exists: subselect

jtuchel
In reply to this post by jtuchel
Hi again,


I've spent a little time with this, although I had decided to give up ;-)
And I am not sure I am getting better in understanding all this, but I thought I'd share a little bit of what I found so far..

So I went and loaded GlorpTests into my VAST image and browse arund a little. And it seems there is a much simpler way to achieve what I want by using anySatisfy: in a Glorp Query.

So I tried this:

    query := SimpleQuery read: KontolinoPurchase. 
    query where: [:k |
        (k package id = 1) AND: (k dateOfPurchase < Date today) AND: (k dateWelcomeMail = nil) AND: (k company users anySatisfy: [::usr| usr isActive])].

And this will also transform to an EXISTS subselect where the join is correct:

SELECT t1.id, "many more"
 FROM (DB2INST1.PURCHASE t1 INNER JOIN DB2INST1.COMPANY t2 ON (t1.company_id = t2.id))
 WHERE (
(((t1.package_id = 1)
AND (t1.date < '2019-05-20'))
AND (t1.date_welcome_mail IS NULL))
AND  EXISTS (
SELECT t3.id
 FROM DB2INST1.USER t3
 WHERE ((t3.active = 1) AND (t2.id = t3.company_id))))


I wasn't aware of the fact that you can use anySatisfy: in query blocks, but this is much more convenient and makes the ST and SQL code much nicer.

This brings me to a new conclusion: since several people told me here and privately that they didn't encounter this problem (most of them using VisualWorks and/or another Database), there might be something wrong with the definitition of the EXIST and NOT EXISTS function in either DB2Platform on all Glorp Dialects or in the DB2Platform in the Glorp port on VAST.

DB2Platform>>#initializeFunctions overrides the defintion of EXISTS and NOT EXISTS from DatabasePlatform. Unfortunately it does so in write-only manner that I am unsable to understand....


    "Like Oracle, SQL Server doesn't allow functions like EXISTS in a field list,
    but will allow a select there as an argument to a function, such as CASE.
    So print it that way if we're in the select list."

    baseExists := functions at: #exists:.
    dbSpecificExists := DualRoleFunction new.
    dbSpecificExists function: '#exists:'.
    dbSpecificExists whereClauseVersion: baseExists.
    selectList :=
        Case new argumentTypes: (Array with: (self varchar: 1) with: self integer with: self integer).
    selectList argumentModifierBlock: [:function :args |
        function base: args first.
        Array with: 'x' asGlorpExpression with: 1 asGlorpExpression with: 0 asGlorpExpression].
    dbSpecificExists selectListVersion: selectList.
    dbSpecificExists type: self integer.
    functions at: #exists: put: dbSpecificExists.

Please note: the comment mentions SQL server, but this snippet is taken from DB2Platform. Maybe that is a hint?


I will look a bit further, but for now I'll see if I can express some of my EXISTS subqueries using anySatisfy: and thus make our Application a bit faster in some places...

This leads me to a very interesting question. If EXIST can be done with anySatisfy: in a query Block, chances are I can also do a NOT EXIST using noneSatisfy:, right?


As always, thanks for listening and giving me hooks for looking at the right places. Even if exists: and notExists: don't work for me on VAST/DB2, I have the feeling I can express most of what I need using #anySatisfy: and #noneSatisfy: (or with anySatisfy: not).


Joachim





--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/ca5cb7da-37c5-4f77-b14d-a11d8a7f38ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

RE: Problems with exists: subselect

Wallen, David

Hi Joachim,

 

It looks like your version of GlorpDatabase may be from 2012. The #initialize function and many other things have been updated since then, all available in the Cincom public repository.

 

Dave

 

Dave Wallen 
Software Engineer
 

https://no-cache.hubspot.com/cta/default/431576/c36613c8-e7ed-43e4-96aa-21da1a227630.png

blank
office:
513-612-2003
website: www.cincomsmalltalk.com
email: [hidden email]
 

 
 
 https://no-cache.hubspot.com/cta/default/431576/0488e96d-1f19-4f15-9229-6366998fd492.png   https://no-cache.hubspot.com/cta/default/431576/98535c75-36a7-4ad2-886f-59aed10b7d2d.png   https://no-cache.hubspot.com/cta/default/431576/1b963ee4-96da-4a8d-92b5-dc1c5570e9ad.png   https://no-cache.hubspot.com/cta/default/431576/dc3c920a-1832-4080-afb7-2e78ad67d354.png   https://no-cache.hubspot.com/cta/default/431576/df552d48-897f-4524-babf-2e9a83340091.png

 

--- CONFIDENTIALITY STATEMENT ---

This e-mail transmission contains information that is intended to be privileged and confidential. It is intended only for the addressee named above. If you receive this e-mail in error, please do not read, copy or disseminate it in any manner. If you are not the intended recipient, any disclosure, copying, distribution or use of the contents of this information is prohibited, please reply to the message immediately by informing the sender that the message was misdirected. After replying, please erase it from your computer system. Your assistance in correcting this error is appreciated.

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of jtuchel
Sent: Monday, May 20, 2019 5:36 AM
To: glorp-group
Subject: Re: Problems with exists: subselect

 

Hi again,

 

 

I've spent a little time with this, although I had decided to give up ;-)

And I am not sure I am getting better in understanding all this, but I thought I'd share a little bit of what I found so far..

 

So I went and loaded GlorpTests into my VAST image and browse arund a little. And it seems there is a much simpler way to achieve what I want by using anySatisfy: in a Glorp Query.

 

So I tried this:

 

    query := SimpleQuery read: KontolinoPurchase. 

    query where: [:k |
        (k package id = 1) AND: (k dateOfPurchase < Date today) AND: (k dateWelcomeMail = nil) AND: (k company users anySatisfy: [::usr| usr isActive])].

And this will also transform to an EXISTS subselect where the join is correct:

 

SELECT t1.id, "many more"
 FROM (DB2INST1.PURCHASE t1 INNER JOIN DB2INST1.COMPANY t2 ON (t1.company_id = t2.id))
 WHERE (

(((t1.package_id = 1)

AND (t1.date < '2019-05-20'))

AND (t1.date_welcome_mail IS NULL))

AND  EXISTS (

SELECT t3.id
 FROM DB2INST1.USER t3
 WHERE ((t3.active = 1) AND (t2.id = t3.company_id))))

 

 

I wasn't aware of the fact that you can use anySatisfy: in query blocks, but this is much more convenient and makes the ST and SQL code much nicer.

 

This brings me to a new conclusion: since several people told me here and privately that they didn't encounter this problem (most of them using VisualWorks and/or another Database), there might be something wrong with the definitition of the EXIST and NOT EXISTS function in either DB2Platform on all Glorp Dialects or in the DB2Platform in the Glorp port on VAST.

 

DB2Platform>>#initializeFunctions overrides the defintion of EXISTS and NOT EXISTS from DatabasePlatform. Unfortunately it does so in write-only manner that I am unsable to understand....

 

 

    "Like Oracle, SQL Server doesn't allow functions like EXISTS in a field list,
    but will allow a select there as an argument to a function, such as CASE.
    So print it that way if we're in the select list."

    baseExists := functions at: #exists:.
    dbSpecificExists := DualRoleFunction new.
    dbSpecificExists function: '#exists:'.
    dbSpecificExists whereClauseVersion: baseExists.
    selectList :=
        Case new argumentTypes: (Array with: (self varchar: 1) with: self integer with: self integer).
    selectList argumentModifierBlock: [:function :args |
        function base: args first.
        Array with: 'x' asGlorpExpression with: 1 asGlorpExpression with: 0 asGlorpExpression].
    dbSpecificExists selectListVersion: selectList.
    dbSpecificExists type: self integer.
    functions at: #exists: put: dbSpecificExists.

 

Please note: the comment mentions SQL server, but this snippet is taken from DB2Platform. Maybe that is a hint?

 

 

I will look a bit further, but for now I'll see if I can express some of my EXISTS subqueries using anySatisfy: and thus make our Application a bit faster in some places...

 

This leads me to a very interesting question. If EXIST can be done with anySatisfy: in a query Block, chances are I can also do a NOT EXIST using noneSatisfy:, right?

 

 

As always, thanks for listening and giving me hooks for looking at the right places. Even if exists: and notExists: don't work for me on VAST/DB2, I have the feeling I can express most of what I need using #anySatisfy: and #noneSatisfy: (or with anySatisfy: not).

 

 

Joachim

 

 

 

 

 

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/ca5cb7da-37c5-4f77-b14d-a11d8a7f38ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/BY5PR13MB3031318FC5E48EE1B7D829C3C9060%40BY5PR13MB3031.namprd13.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with exists: subselect

jtuchel
In reply to this post by jtuchel
To make things a little more interesting: I forgot to mention that we actually do use exists: and notExists: for some queries and have been doing so for years. So it is not a general problem with these queries. This also means my last "suspect" about #initializeFunctions is probably not very accurate ;-)

I guess it's more likely there are some differences between the ones that work and ones that don't in the information provided in the mappings or such.

But I've heard from several sources in the meantime that this problem once occured also in VisualWorks and on Postgres and has been fixed in Glorp on VW a while ago now... so chances are this is a VAST only problem these days...

Joachim






Am Montag, 20. Mai 2019 14:36:08 UTC+2 schrieb jtuchel:
Hi again,


I've spent a little time with this, although I had decided to give up ;-)
And I am not sure I am getting better in understanding all this, but I thought I'd share a little bit of what I found so far..

So I went and loaded GlorpTests into my VAST image and browse arund a little. And it seems there is a much simpler way to achieve what I want by using anySatisfy: in a Glorp Query.

So I tried this:

    query := SimpleQuery read: KontolinoPurchase. 
    query where: [:k |
        (k package id = 1) AND: (k dateOfPurchase < Date today) AND: (k dateWelcomeMail = nil) AND: (k company users anySatisfy: [::usr| usr isActive])].

And this will also transform to an EXISTS subselect where the join is correct:

SELECT <a href="http://t1.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ft1.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFUSAPqycKag5PTtPTdajv-cdD10A&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ft1.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFUSAPqycKag5PTtPTdajv-cdD10A&#39;;return true;">t1.id, "many more"
 FROM (DB2INST1.PURCHASE t1 INNER JOIN DB2INST1.COMPANY t2 ON (t1.company_id = <a href="http://t2.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ft2.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNG52wQIzs7juXMS43cxwYjRWmvT1g&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ft2.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNG52wQIzs7juXMS43cxwYjRWmvT1g&#39;;return true;">t2.id))
 WHERE (
(((t1.package_id = 1)
AND (t1.date < '2019-05-20'))
AND (t1.date_welcome_mail IS NULL))
AND  EXISTS (
SELECT <a href="http://t3.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ft3.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH_EPlF1ODAZ-wj5HoGmWdQTaGSGQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ft3.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH_EPlF1ODAZ-wj5HoGmWdQTaGSGQ&#39;;return true;">t3.id
 FROM DB2INST1.USER t3
 WHERE ((t3.active = 1) AND (<a href="http://t2.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ft2.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNG52wQIzs7juXMS43cxwYjRWmvT1g&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ft2.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNG52wQIzs7juXMS43cxwYjRWmvT1g&#39;;return true;">t2.id = t3.company_id))))


I wasn't aware of the fact that you can use anySatisfy: in query blocks, but this is much more convenient and makes the ST and SQL code much nicer.

This brings me to a new conclusion: since several people told me here and privately that they didn't encounter this problem (most of them using VisualWorks and/or another Database), there might be something wrong with the definitition of the EXIST and NOT EXISTS function in either DB2Platform on all Glorp Dialects or in the DB2Platform in the Glorp port on VAST.

DB2Platform>>#initializeFunctions overrides the defintion of EXISTS and NOT EXISTS from DatabasePlatform. Unfortunately it does so in write-only manner that I am unsable to understand....


    "Like Oracle, SQL Server doesn't allow functions like EXISTS in a field list,
    but will allow a select there as an argument to a function, such as CASE.
    So print it that way if we're in the select list."

    baseExists := functions at: #exists:.
    dbSpecificExists := DualRoleFunction new.
    dbSpecificExists function: '#exists:'.
    dbSpecificExists whereClauseVersion: baseExists.
    selectList :=
        Case new argumentTypes: (Array with: (self varchar: 1) with: self integer with: self integer).
    selectList argumentModifierBlock: [:function :args |
        function base: args first.
        Array with: 'x' asGlorpExpression with: 1 asGlorpExpression with: 0 asGlorpExpression].
    dbSpecificExists selectListVersion: selectList.
    dbSpecificExists type: self integer.
    functions at: #exists: put: dbSpecificExists.

Please note: the comment mentions SQL server, but this snippet is taken from DB2Platform. Maybe that is a hint?


I will look a bit further, but for now I'll see if I can express some of my EXISTS subqueries using anySatisfy: and thus make our Application a bit faster in some places...

This leads me to a very interesting question. If EXIST can be done with anySatisfy: in a query Block, chances are I can also do a NOT EXIST using noneSatisfy:, right?


As always, thanks for listening and giving me hooks for looking at the right places. Even if exists: and notExists: don't work for me on VAST/DB2, I have the feeling I can express most of what I need using #anySatisfy: and #noneSatisfy: (or with anySatisfy: not).


Joachim





--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/e6f3a006-e635-412f-afec-6b90d43e295e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.