HCC Compression on Oracle Live SQL

Posted in: Oracle

I’ve written previously about “Oracle Live SQL”, a free service from Oracle where you can try your coding skills and learn using its vast code library. Today I want to mention one of its other features which may not be widely known: compression.

If you use the service, you know that it provides only a few megabytes for your temporary schema which is usually enough for simple small tables and indexes to use in your tests. Also, they supply public schemas with some sample data. But what if you want to feed it more of your own data for your tests? You can actually use Oracle Compression for your objects. And you may be surprised to learn that you will have not only the expected basic and OLTP compression, but also a proper HCC compression. I think from that you can guess what kind on the backend you have for the service!

Let’s test and compare different types of conversions. As I’ve said, you don’t have too much space in your schema for tests, hence you are limited to a small dataset. Let’s create a table and check.

CREATE TABLE t1_nocompress AS SELECT * FROM 
(SELECT rownum t1_id, object_id p1, object_name p2, owner p3 FROM all_objects),(SELECT rownum FROM dual CONNECT BY LEVEL <=2);
 
SELECT segment_name,blocks,bytes/1024 bytes_k FROM user_segments;

From that I got an 8192 Kb segment which may not be sufficiently big to see a real difference in size for different compression types, but I’ll try anyway. Let’s try to create an object with advanced compression and see if it saves us any space.

DROP TABLE t1_nocompress purge;
 
CREATE TABLE t1_advcompress ROW store compress advanced AS SELECT * FROM 
(SELECT rownum t1_id, object_id p1, object_name p2, owner p3 FROM all_objects),(SELECT rownum FROM dual CONNECT BY LEVEL <=2);

So, instead of 8192 Kb, we have 7168 Kb. The savings of 1M of space is not very impressive. What if we tried Hybrid Columnar Compression (HCC)?

DROP TABLE t1_advcompress purge;
 
CREATE TABLE t1_hccquerylow COLUMN store compress FOR query low AS SELECT * FROM 
(SELECT rownum t1_id, object_id p1, object_name p2, owner p3 FROM all_objects),(SELECT rownum FROM dual CONNECT BY LEVEL <=2);

The segment size decreased to 2048 Kb or 4 times. That looks way better. What if we try the HCC with query high compression level?

DROP TABLE t1_hccquerylow purge;
 
CREATE TABLE t1_hccqueryhigh COLUMN store compress FOR query high AS SELECT * FROM 
(SELECT rownum t1_id, object_id p1, object_name p2, owner p3 FROM all_objects),(SELECT rownum FROM dual CONNECT BY LEVEL <=2);

The segment was only 832 Kb which is almost a 10 times space reduction. As the result, we could create a table with 10 times more rows. The original table was created with 109054 rows.

DROP TABLE t1_hccqueryhigh purge;
 
CREATE TABLE t1_hccqueryhigh COLUMN store compress FOR query high AS SELECT * FROM 
(SELECT rownum t1_id, object_id p1, object_name p2, owner p3 FROM all_objects),(SELECT rownum FROM dual CONNECT BY LEVEL <=20);
 
SELECT COUNT(*) FROM t1_hccqueryhigh;

Now we have a table with 1090540 rows and the segment size is still 8192 Kb. Hence, if you need a 1 million row table for your Oracle Live SQL test, HCC compression could be your savior.

It is pretty good to have HCC compression and database in memory features on a free service for developers. It may help you to understand how it works and maybe test some of your scenarios. Happy coding everyone.

email

Interested in working with Gleb? Schedule a tech call.

About the Author

Regarded by his peers as an Oracle guru, Gleb is known for being able to resolve any problem related to Oracle. He loves the satisfaction of troubleshooting, and his colleagues even say that seeking Gleb’s advice regarding an issue is more efficient than looking it up. Gleb enjoys the variety of challenges he faces while working at Pythian, rather than working on the same thing every day. His areas of speciality include Oracle RAC, Exadata, RMAN, SQL tuning, high availability, storage, performance tuning, and many more. When he’s not working, running, or cycling, Gleb can be found reading.

No comments

Leave a Reply

Your email address will not be published. Required fields are marked *