When we should use RDB methods over Obj methods

Hi,

Obj methods are always the first choice. However, there may be times when you need to opt for RDB methods. In this post, I will share such use cases based on my experiences.

1. Differences between Obj methods and RDB methods

No Features Obj methods RDB methods
1 Supported table
- Internal table
- External table

- External table only


(RDB methods can work on only exposed columns, not Blob)

2 SQL Simple SQL Complex SQL
3 Transaction management Supported Not supported
4 Calling stored procedure Not possible Possible
5 Calling DBMS function Not possible Possible

Some people seem to believe that Obj methods must be exclusively used for internal table, and RDB methods must be exclusively used for external table. This is not correct. Obj methods can be used for both internal and external tables. Traditional relational tables without Blob in customer’s external database site can be accessed by Obj methods. Data Type tables created in “CustomerDATA” have no Blob columns and this can be also accessed by Obj methods.

Obj methods supports transaction management or deferred save while in RDB methods update is auto-committed implicitly in the step right away. This may sometimes cause inconvenience - for example, when you want to manage transaction on multiple tables, if the first update fails for whatever reasons, then you want to rollback and cancel other update to avoid data inconsistency. This is only manageable in Obj methods. Now, if Obj methods are always recommended, when exactly should we use RDB methods over Obj methods? I will explain four examples below.

2. Things that only RDB methods can do

2-1. Complex SQL

Obj methods can only search instances of a single class with simple SQL whereas RDB methods can handle complex SQL that includes involving more than one class along with JOIN clause, subqueries, UNION clause, etc. For example, Assign-Worklist and Assign-Workbasket are similar but two separate tables derived from Assign- class. If you want to construct a single Page List of result set combining the data from the result of two tables, you need to write SQL with UNION clause in Connect SQL as below (*). Obj method can’t handle this.

  • As an alternative, this UNION requirement can be also achieved by creating a View at database level so from PRPC you can easily query against a single class.

2-2. Calling stored procedure

Stored procedure is a group of one or more pre-compiled SQL statements that are stored in a database. In general, stored procedure is not recommended if you are creating it from scratch because this approach will reduce the portability of your Pega application and it is hard to maintain. However, if customer already has lots of stored procedures that interact with their existing database, it will be easier to just reuse their assets (Wrap and Renew).

In order to call stored procedure, you need to use RDB methods (Connect SQL). I have documented how to call stored procedure in a separate article. Please see https://support.pega.com/discussion/how-call-stored-procedure-oracle.

2-3. Calling DBMS function

All database software provides vendor-specific DBMS function. It is not recommended to use it because it will reduce the portability of your Pega application. However, in certain situations you may not have other choice. In my experience, I had to use Oracle’s function to convert character set of text that are integrated from external systems. For example, to convert string “あいうえお” from Shift-JIS to EUC, CONVERT function is required. You need to use Connect SQL to call DBMS function.

SELECT CONVERT('あいうえお', 'JA16EUC', 'JA16SJIS') FROM DUAL;

2-4. Performance

If some of you believe RDB methods are always much faster than Obj methods, that is not true. I have measured the performance of Obj-Browse and RDB-List against very large dataset, but no significant difference was observed. What makes a big difference is when you update or delete multiple records at once filtering by certain conditions. No such equivalent Obj methods are currently available and if you want to accomplish this by Obj methods, you need to first obtain a set of records by Obj-Browse, and then looping over the result set perform acquire lock, update, and commit successively. In Obj methods, acquiring / releasing a lock involves PR_SYS_LOCKS table insert / delete for each record. Also, inserting history records are triggered by itself. On the other hand, in RDB methods, only the main table is updated and no locking or histories are required. If the number of records is a couple of hundreds, Obj method may be acceptable, but if the it is massive, consider switching to RDB methods. I have conducted a quick experiment of DELETE / UPDATE operations against 1,000,000 records to get some idea how much they are different. You can see RDB methods are much faster than Obj methods.

No Operation Obj methods RDB methods
1 DELETE 1,000,000 records 30 minutes 3 seconds 4 seconds
2 UPDATE 1,000,000 records 40 minutes 52 seconds 13 seconds

Hope this helps.

Thanks,

@KenshoTsuchihashi One more drawback of RDB are they are not DB convertable i.e. (ORACLE/SQLSERVER/DB2/POSTGRES). If you are using Obj you can import rap from one pega supported db to another it will work in rbd you need to rewrite as some syntax are not same for the supported database.

@KenshoTsuchihashi This is a great post. You’ve done an excellent job in comparing the two approaches.

One point of feedback I would offer is there is additional alterative–that is using report definitions for your query. By using report definitions, you address some of the limitations of using Obj- methods. Namely:

  • you can join across tables/classes

  • you can take advantage of summarization and aggregation

I suspect that you may see a slight overhead with respect to performance as several additional rules are invoked when running a report definition vs directly calling an Obj/RDB method.

@KenshoTsuchihashi Good Post. Thanks for sharing

@RobertD55

That’s right, Report Definition can handle JOIN and Sub Report. You can call Report Definition from an activity by calling Rule-Obj-Report-Definition.pxRetrieveReportData, and that is another option.

Thanks,

@KenshoTsuchihashi Which one has better performance report defination or RDB where requirements have mutiple table joins .

Please share your thoughts.

IS RDB-list with joins/sub query and same joins/sub reports which one has better performance on internal tables.

@pramodkumar k

I have done a quick PoC in my local environment. I created two tables - Employee and Dept. Then I populated Employee table with 1,000,000 sample data. I performed INNER JOIN on these tables (see below) using RDB methods and calling Report Definition from activity to compare the performance.

I have measured elapsed time for (1) directly running SQL from pgAdmin, (2) RDB methods, and (3) Report Definition. I tested 10 times for each approach and calculated the average elapsted time, as shown below.

Approach Average elapsted time
(1) pgAdmin 0.3822 seconds
(2) RDB methods 0.4628 seconds
(3) Calling Report Definition from activity 3.6192 seconds

Of course pgAdmin is the fastest as there is no Pega overhead. For RDB methods vs Report Definition, we can see that RDB methods are about 8 times faster. Hope this clarifies your question.

Thanks,

Hi @KenshoTsuchihashi

Your articles are always superb and very nice, and I really appreciate your efforts.

I have a doubt, Why RDB methods will not work for BLOB Colom? (That External DB Doesn’t have BLOB Coloms)

Can you explain more about this? That will be helpful.

Thanks,

Ashok

@Bhumireddy The RDB will not work on the pega blob column however any other external column that is blob you can use it.

This is because the Pega blob column is encrypted by the Pega algorithm and so the LOB function to read the blob column will not help with this.

@gasharma

> This is because the Pega blob column is encrypted by the Pega algorithm.

This is not correct. Pega Blob column is not encrypted by default unless you explicitly do so. Apparently regular SQL can’t interpret Pega Blob as it is obfuscated in Pega’s proprietary manner. Pega Blob has to be read / written thru Pega tool.

https://support.pega.com/discussion/understanding-pega-blob-and-udf

Thanks,

Hi @KenshoTsuchihashi,

Thank you for the clarification. If you have not exposed the column, and then if you are trying to use some property in RDB Delete (SQL Delete Method), we will see this below error.

If you expose the property, then we will try to delete the value of some property; it will delete the whole work object data and it is deleting the whole data in BLOB too.

It should delete only the Data in Exposed column data, right? or both BLOB and exposed column data?

When Using the RDB-SAVE, It is updated in Only Exposed Column and Not Updated in BLOB Column, Same thing Not happened in RDB-Delete.

Your mentioned Note: RDB methods can work on only exposed columns, not Blob

Note: I am directly testing into work class.

and another query: Which is the best Practice used for Declare Trigger for OBJ Methods vs RDB Methods?

As you mentioned the Transaction management: Not supported (RDB Methods).

Execute an activity declaratively based on Events (Transactional).

Declare Trigger rules to cause an activity to run when instances of a specific class are created, updated, or deleted in the database. This implements a form of forward chaining.

Thanks,

Ashok

Hi @Gaurav25,

I am successfully able to retrieve and browse records stored in the pzPVStream (BLOB column) of the pc_work table using either the RDB-Open or RDB-List methods, leveraging the pr_read_from_stream function within a Connect-SQL rule

@KenshoTsuchihashi This is not good way to open or browse the records ? Please let me know.

Thanks,

Ashok

Hi @Bhumireddy,

This is not good as Pega is planning to stop UDF support in future release, one more point to understand the main idea to use connect sql is :“Use Connect SQL rules when your application needs to run complex Structured Query Language statements such as joins or stored procedures to update or extract information from an external database.

For Pega Database its best to use obj-methods or RD.

Quote for thought: “Building the wrong thing isn’t just a waste of time — it happens when you use a drill where a hammer is needed.”

@Gaurav25

Okay, I’m taking about this → (RDB methods can work on only exposed columns, not Blob)

Hi @Bhumireddy

RDB methods provide you options to run the native sql query from pega. If you need to read the blob content you need to add the pr_read_from_steam function in the sql query which will allow you to read the pzpvstram blob column.

If you have created custom column type as blob you can use that directly in your sql function,example below.

select utl_raw.cast_to_varchar2(dbms_lob.substr(BLOB_FIELD)) from TABLE_WITH_BLOB