<?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: Simple SQL statement write-locks a table for many hours, SAS should be able to figure out what t in Developers</title>
    <link>https://communities.sas.com/t5/Developers/Simple-SQL-statement-write-locks-a-table-for-many-hours-SAS/m-p/780045#M1331</link>
    <description>&lt;P&gt;My guess that for every row your SQL deletes, SAS is updating the index. That will definitely be slow. Try dropping indexes, then deleting rows.&lt;/P&gt;</description>
    <pubDate>Fri, 12 Nov 2021 20:54:39 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2021-11-12T20:54:39Z</dc:date>
    <item>
      <title>Simple SQL statement write-locks a table for many hours, SAS should be able to figure out what to do</title>
      <link>https://communities.sas.com/t5/Developers/Simple-SQL-statement-write-locks-a-table-for-many-hours-SAS/m-p/779975#M1329</link>
      <description>&lt;P&gt;Hi to y'all!&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a table that resides on a SPD server.&amp;nbsp; I call it SPD_TABLE in this example.&amp;nbsp; It has 4 indexes.&amp;nbsp; 3 simple ones and 1 composite that is unique. For the example I call the columns for this unique index&amp;nbsp; REC_RK and VALID_FROM.&amp;nbsp; This is the UNIQUE KEY.&amp;nbsp; I have about 80.000 rows in this table. All the REC_RK's are &amp;gt; 6000000.&amp;nbsp; &amp;nbsp;So now I want to empty this table.&amp;nbsp; I write:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&amp;nbsp; delete from libforfun.spd_table where rec_rk ne 1 ;quit;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This take hours if it ends at all (haven't had the patience) and write-locks the table!&amp;nbsp; What is it that the compiler cannot figure out?&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":face_with_rolling_eyes:"&gt;🙄&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To avoid this I coded a simple work around:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. data bla_bla;&amp;nbsp;set&amp;nbsp;&amp;nbsp;libforfun.spd_table; where&amp;nbsp;rec_rk eq 1; run;&amp;nbsp; &amp;nbsp; /*result - an empty table */&lt;/P&gt;
&lt;P&gt;2. data&amp;nbsp;libforfun.spd_table; set bla_bla; run;&amp;nbsp; &amp;nbsp; /*problem solved*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But WHY is the other option not done in a jiffy ??? Where is the bug that I cannot see?&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;Longimanus.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 14:15:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Simple-SQL-statement-write-locks-a-table-for-many-hours-SAS/m-p/779975#M1329</guid>
      <dc:creator>Longimanus</dc:creator>
      <dc:date>2021-11-12T14:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: Simple SQL statement write-locks a table for many hours, SAS should be able to figure out what t</title>
      <link>https://communities.sas.com/t5/Developers/Simple-SQL-statement-write-locks-a-table-for-many-hours-SAS/m-p/779987#M1330</link>
      <description>&lt;P&gt;Deleting all of the observations from a existing dataset is NOT something you should be doing with SAS.&lt;/P&gt;
&lt;P&gt;Why not just make a new dataset with zero observations?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data replace;
  set replace(obs=0);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Nov 2021 14:52:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Simple-SQL-statement-write-locks-a-table-for-many-hours-SAS/m-p/779987#M1330</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-12T14:52:54Z</dc:date>
    </item>
    <item>
      <title>Re: Simple SQL statement write-locks a table for many hours, SAS should be able to figure out what t</title>
      <link>https://communities.sas.com/t5/Developers/Simple-SQL-statement-write-locks-a-table-for-many-hours-SAS/m-p/780045#M1331</link>
      <description>&lt;P&gt;My guess that for every row your SQL deletes, SAS is updating the index. That will definitely be slow. Try dropping indexes, then deleting rows.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 20:54:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Simple-SQL-statement-write-locks-a-table-for-many-hours-SAS/m-p/780045#M1331</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-11-12T20:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: Simple SQL statement write-locks a table for many hours, SAS should be able to figure out what t</title>
      <link>https://communities.sas.com/t5/Developers/Simple-SQL-statement-write-locks-a-table-for-many-hours-SAS/m-p/780108#M1332</link>
      <description>I tested it under PC version sas , have no problem.But yours is under SPDServer ,totally different engine.&lt;BR /&gt;Maybe as SASKiwi said the problem is from index . try to drop index before delete.</description>
      <pubDate>Sat, 13 Nov 2021 12:25:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Simple-SQL-statement-write-locks-a-table-for-many-hours-SAS/m-p/780108#M1332</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-11-13T12:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: Simple SQL statement write-locks a table for many hours, SAS should be able to figure out what t</title>
      <link>https://communities.sas.com/t5/Developers/Simple-SQL-statement-write-locks-a-table-for-many-hours-SAS/m-p/780110#M1333</link>
      <description>&lt;P&gt;Use your workaround, but don't forget to recreate the indexes (if they are needed anyway on SPD tables). DELETE will only mark the observations as deleted, but not free the space.&lt;/P&gt;
&lt;P&gt;Run this for reference:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cars;
set sashelp.cars;
do i = 1 to 10;
  output;
end;
run;

proc contents data=cars;
run;

proc sql;
delete from cars where origin ne "moon";
quit;

proc contents data=cars;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will see that the filesize does not change.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Nov 2021 13:38:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Simple-SQL-statement-write-locks-a-table-for-many-hours-SAS/m-p/780110#M1333</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-13T13:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: Simple SQL statement write-locks a table for many hours, SAS should be able to figure out what t</title>
      <link>https://communities.sas.com/t5/Developers/Simple-SQL-statement-write-locks-a-table-for-many-hours-SAS/m-p/780131#M1334</link>
      <description>&lt;P&gt;With SPDS did you consider TRUNCATE? That should be very fast.&lt;/P&gt;
&lt;P&gt;Docu &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/spdsag/n1o5phkhxda9orn1puab1yshnili.htm" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Nov 2021 09:14:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Simple-SQL-statement-write-locks-a-table-for-many-hours-SAS/m-p/780131#M1334</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-11-14T09:14:43Z</dc:date>
    </item>
  </channel>
</rss>

