BookmarkSubscribeRSS Feed

DELETE Your Teradata Data Fast!

Started ‎01-24-2014 by
Modified ‎03-20-2017 by
Views 8,170

It was late Friday afternoon, but then it's usually late Friday when these calls come in. The voice on the phone hurriedly said, "It is taking over an hour to delete all the rows from my Teradata table! Does Teradata have a TRUNCATE command?"

 

It was a consulting friend who was working on a Customer's Teradata Server. This meant that dropping and recreating the table was not an option.

 

My friend needed the Teradata version of the ORACLE TRUNCATE command. One problem, there isn't a Teradata version of that command.

 

What's so special about TRUNCATE?

 

Well, the Oracle TRUNCATE command isn't logged which means there is very little overhead -- it is fast. Wicked fast! The command also resets the high water mark for the table. Oracle will read empty tablespace area, so resetting the high water mark speeds-up queries. The downside is that since there is no logging, it is an unrecoverable action.

 

Fortunately there is a way to very rapidly delete all the rows from a Teradata table. It isn't as simple as TRUNCATE but it does work well. This method bypasses the Teradata journaling facility -- which makes it non recoverable. The official name for this is the Fast Path DELETE. The trick here is the DELETE command has to occur during a single transaction.

 

You can invoke the Fast Path Delete via explicit pass-through using ANSI or Teradata mode. Here are some example:

 

Teradata Mode Fast Path DELETE example:

proc sql;

    connect to teradata (server=MyServ database=MyDB MODE=TERADATA user=MyUserid password=mypasswd);

    execute (BEGIN TRANSACTION; DELETE mytable ALL; END TRANSACTION; ) by teradata;

quit;

 

ANSI Mode Fast Path DELETE example:

proc sql;

    connect to teradata (server=MyServ database=MyDB user=MyUserid password=mypasswd MODE=ANSI);

    execute (DELETE mytable ALL; COMMIT; ) by teradata;

quit;

 

There is a paper on SAS' web site that covers this topic as well as many others. You can find it here

Version history
Last update:
‎03-20-2017 02:37 PM
Updated by:
Contributors

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags