<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: NOTE: The execution of this query involves performing one or more Cartesian product joins in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873523#M345147</link>
    <description>&lt;P&gt;Why do you need to improve performance when the query real time is less than 1 second? Are you getting the right result set?&lt;/P&gt;</description>
    <pubDate>Wed, 03 May 2023 03:55:09 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2023-05-03T03:55:09Z</dc:date>
    <item>
      <title>NOTE: The execution of this query involves performing one or more Cartesian product joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873367#M345076</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to know is there any way I can optimize this join. I am getting notes :&lt;/P&gt;
&lt;P&gt;NOTE: The execution of this query involves performing one or more Cartesian product joins that can not be optimized. mywork.dates&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;proc&lt;/SPAN&gt; &lt;SPAN&gt;sql&lt;/SPAN&gt; &lt;SPAN&gt;noprint&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;create&lt;/SPAN&gt; &lt;SPAN&gt;table&lt;/SPAN&gt;&amp;nbsp;mywork.&lt;SPAN&gt;dates as &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; select &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;distinct&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a.prod_sk&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a.geo_sk&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; b.date_sk&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; b.fiscal_start_dt&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; b.fiscal_end_dt&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; from &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mywork&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;tmp_plan_actuals_pgr a&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mylib&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;date_nm b&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; where b.fiscal_start_dt &lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;=&lt;/SPAN&gt; &lt;SPAN&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN&gt;min_start_dt.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;and b.fiscal_end_dt &lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;=&lt;/SPAN&gt; &lt;SPAN&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN&gt;max_end_dt.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and date_lvl_no &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN&gt;time_low_lvl.&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;quit&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;&amp;amp;min_start_dt. ,&amp;nbsp;&amp;amp;max_end_dt. ,&amp;nbsp;&amp;nbsp;&amp;amp;time_low_lvl these have some values . these are getting created in previous steps and totally independent from the tables present in join.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Please help.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 02 May 2023 13:37:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873367#M345076</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2023-05-02T13:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: NOTE: The execution of this query involves performing one or more Cartesian product joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873370#M345079</link>
      <description>&lt;P&gt;A Cartesian join takes all records of data set 1 and merges them with all records in data set 2. If data set 1 has n1 records and data set 2 has n2 records, then the Cartesian join will have n1*n2 records (which may be reduced by a WHERE statement, but I think first all records are created and then those that don't meet the where condition are deleted). If n1 and n2 are large, this will take a long time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only way to "optimize" is if you can replace the Cartesian join with some other type of join. Maybe that's possible, maybe that's not possible, you tell us.&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2023 13:48:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873370#M345079</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-02T13:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: NOTE: The execution of this query involves performing one or more Cartesian product joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873381#M345084</link>
      <description>&lt;P&gt;Which data set has the variable date_lvl_no?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without example data and expected results we can't come up with much optimization and when you use just a comma between two sets that is the request for a Cartesian join. SAS provides a note about such in case that wasn't your intent.&lt;/P&gt;
&lt;PRE&gt;from set1 , set2&lt;/PRE&gt;
&lt;P&gt;You might be able to improve performance by sub-setting data earlier such as:&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
   create table mywork.dates as
    select
        distinct
        a.prod_sk,
        a.geo_sk,
        b.date_sk,
        b.fiscal_start_dt,
        b.fiscal_end_dt
    from
        mywork.tmp_plan_actuals_pgr a,
        ( select * from mylib.date_nm 
            where fiscal_start_dt &amp;gt;= &amp;amp;min_start_dt.
               and fiscal_end_dt &amp;lt;= &amp;amp;max_end_dt.) as b
        where date_lvl_no = &amp;amp;time_low_lvl.;
    quit;&lt;/PRE&gt;
&lt;P&gt;Do the same about only selecting the records where date_lvl_no is desired from which set it comes from, which is why I asked.&lt;/P&gt;
&lt;P&gt;This reduces the number of joins between the two sets which MAY significantly improve run time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Caution: Is B.fiscal_end_dt ever missing? If it is missing then it is less than any value for &amp;amp;max_end_dt. Is that your intend or did you only want the fiscal_end_dt when not missing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2023 14:40:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873381#M345084</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-02T14:40:25Z</dc:date>
    </item>
    <item>
      <title>Re: NOTE: The execution of this query involves performing one or more Cartesian product joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873443#M345113</link>
      <description>Thank i tried as you suggested . Please refer  below comparison .&lt;BR /&gt;without applying  the sub setting method &lt;BR /&gt;NOTE: The execution of this query involves performing one or more Cartesian product joins that can not be optimized.&lt;BR /&gt;NOTE: Table mywork.dates created, with 10790 rows and 5 columns.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;      real time           0.35 seconds&lt;BR /&gt;      cpu time            0.51 seconds&lt;BR /&gt;&lt;BR /&gt;with apply sub setting &lt;BR /&gt;&lt;BR /&gt;NOTE: The execution of this query involves performing one or more Cartesian product joins that can not be optimized.&lt;BR /&gt;NOTE: Table mywork.dates created, with 10790 rows and 5 columns.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;      real time           0.39 seconds&lt;BR /&gt;      cpu time            0.53 seconds&lt;BR /&gt;&lt;BR /&gt;I am still getting notes and the its taking more time in sub setting method. . Can you please suggest if I am missing anything.</description>
      <pubDate>Tue, 02 May 2023 17:46:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873443#M345113</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2023-05-02T17:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: NOTE: The execution of this query involves performing one or more Cartesian product joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873485#M345126</link>
      <description>&lt;P&gt;The only way to remove that note is a setting that will suppress all notes. So is not recommended. It is not an error. It is a reminder that such as join is in your code. Such Cartesian joins,&lt;STRONG&gt; by definition&lt;/STRONG&gt;, join every record in one set with every record in the other set. That step cannot be optimized. Ever. Period.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are going to use Cartesian joins it is a good idea to keep a good grasp on your data set sizes and exactly how every element of the data is actually used to get reasonable performance out of everything else.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2023 21:03:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873485#M345126</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-02T21:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: NOTE: The execution of this query involves performing one or more Cartesian product joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873508#M345134</link>
      <description>&lt;P&gt;Are there no key columns that are in both input tables? Your query is missing a join between at least one column in each input table, so that's why you are getting the Cartesian product note.&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2023 00:14:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873508#M345134</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-05-03T00:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: NOTE: The execution of this query involves performing one or more Cartesian product joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873509#M345135</link>
      <description>&lt;P&gt;Cartesian joins&lt;/P&gt;&lt;P&gt;prod&lt;/P&gt;&lt;P&gt;med;&lt;/P&gt;&lt;P&gt;&lt;A href="http://cryphosnegative.blogspot.com/" target="_self"&gt;http://cryphosnegative.blogspot.com/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2023 00:18:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873509#M345135</guid>
      <dc:creator>cryphosnegative</dc:creator>
      <dc:date>2023-05-03T00:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: NOTE: The execution of this query involves performing one or more Cartesian product joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873521#M345145</link>
      <description>There are no key column. I just want to optimize that step to improve performance</description>
      <pubDate>Wed, 03 May 2023 03:48:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873521#M345145</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2023-05-03T03:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: NOTE: The execution of this query involves performing one or more Cartesian product joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873522#M345146</link>
      <description>Sorry , I don't get this. What exactly I have to check in the blog ?</description>
      <pubDate>Wed, 03 May 2023 03:50:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873522#M345146</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2023-05-03T03:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: NOTE: The execution of this query involves performing one or more Cartesian product joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873523#M345147</link>
      <description>&lt;P&gt;Why do you need to improve performance when the query real time is less than 1 second? Are you getting the right result set?&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2023 03:55:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/873523#M345147</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-05-03T03:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: NOTE: The execution of this query involves performing one or more Cartesian product joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/874278#M345408</link>
      <description>the result log is from sample data set, which is very less compare to actual ones</description>
      <pubDate>Sat, 06 May 2023 18:15:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/874278#M345408</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2023-05-06T18:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: NOTE: The execution of this query involves performing one or more Cartesian product joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/874371#M345459</link>
      <description>&lt;P&gt;Show examples of the data (does not need to be REAL data, just something that shows the right relationships).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there really is no variables in common between the two tables then you cannot do anything other than a Cartesian product.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you can fool PROC SQL into not writing the message by just adding a variable to each input and joining on it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is trivial example you can try.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql nowarn;
create table test as
select *
from (select distinct sex,1 as x from sashelp.class) a
   , (select distinct age,1 as x from sashelp.class) b
;
create table test2(drop=x) as
select *
from (select distinct sex,1 as x from sashelp.class) a
full join (select distinct age,1 as x from sashelp.class) b
on a.x=b.x
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;NOTE that&amp;nbsp;the variable&amp;nbsp;&lt;SPAN&gt;date_lvl_no&amp;nbsp;mentioned in your WHERE clause is not output and you do not say where it came from.&amp;nbsp; You could make the problem easier by just excluding those observations from even being considered.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So if DATE_LVL_NO is coming from&amp;nbsp;mylib.date_nm then your query looks like:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table mywork.dates as
select distinct
     a.prod_sk
   , a.geo_sk
   , b.date_sk
   , b.fiscal_start_dt
   , b.fiscal_end_dt
from (select prod_sk,geo_sk,1 as x from mywork.tmp_plan_actuals_pgr) a
full join 
    (select fiscal_start_dt,fiscal_end_dt,date_sk,1 as x
      from mylib.date_nm
      where fiscal_start_dt &amp;gt;= &amp;amp;min_start_dt.
        and fiscal_end_dt &amp;lt;= &amp;amp;max_end_dt.
        and date_lvl_no = &amp;amp;time_low_lvl.
    ) b
on a.x=b.x
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;It might or might not run any faster.&amp;nbsp; But at least you won't get the NOTE in the LOG.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 May 2023 23:55:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/NOTE-The-execution-of-this-query-involves-performing-one-or-more/m-p/874371#M345459</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-07T23:55:52Z</dc:date>
    </item>
  </channel>
</rss>

