How does the create entity selection works in the 4D database?

250 views Asked by At

I'm wondering about how the create entity selection command in the 4D database works. Does that command also re-query data store internally to get entity selection? If yes then which one would be faster to retrieve entity selection from an existing classic 4D records selection? Use-case is I was trying to create a method with a parameter of table primary id and with that id I query data store to get entity selection from an existing classic record selection primary field. So I wondered which one would be optimized whether using an primary field as an argument for a method or an entity selection as an argument for that method. Any view on this would really be helpful. Thanks.

1

There are 1 answers

2
kirkBrooks On

There are actually three questions here.

  1. how CREATE ENTITY SELECTION works. The docs are helpful. You simply pass the classic table name and an entity selection is returned.

  2. it does make a new request to the server for the entity selection.

  3. which is flat out faster is not really relevant because the real issue will be what you do with it and what kind of data is stored in each of the records.

If you use the old style QUERY command the entire result of the query along with all the contents of all the records are returned to you. If the records have lots and lots of fields or some large fields (BLOBs or pictures) that can be slow and create a lot of network traffic.

If you use the new dataClass.query() 4D returns an entity selection of the data which is a reference to the data instead of the data itself. Further, when the results are large or contain large fields that data isn't transmitted until specifically requested. So if you are searching a table of images, let's say, you can search on the title and get an entity selection but until you actually do something with the image itself it isn't sent.

4D has undergone a significant update in the last few years. It essentially has two languages now. The 'classic' language is the one you probably see if you've been given some old database to keep working. The 'new' language is called ORDA and is object based. 'Classic 4D' is familiar to 4D devs who have used it for 20+ years. ORDA is more familiar to folks with modern coding experience. It is also where all the attention to new development is being concentrated.

The strong commitment in 4D to supporting old databases means these two can exist concurrently in a single project. However, injecting ORDA into classic code is often a painful experience if you aren't familiar with both because in classic you are shuffling around the actual data (in terms of records) while in ORDA you deal with references to the data.