micromax / activejdbc

Automatically exported from code.google.com/p/activejdbc
0 stars 0 forks source link

Performance problem with large amount of null valued columns and object.get(attribute)'s tryParent, tryPoly and other fn's #174

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. create table with one column
2. insert at least 200 000 lines with NULL values
3. try to get them through model.get(field name)

What is the expected output? What do you see instead?
expected: quick answer
instead: as the fn does not get a result from the hash comparison, it tries a 
huge load of patterns to try to find the result which results in HUGE amount of 
string comparisons and slows stuff drastically down

What version of the product are you using? On what operating system?
active jdbc 1.4.3 Postgre 9.1, tomcat 7, win 7

Please provide any additional information below.
is it possible to make the fancy field search somehow optional. theres no need 
to go through polymorphs and others and do a lot of comparisons("gsub" function)

if you select 200 000 results from a table which has 2 columns as nulls it will 
result in ~80M invocations of "gsub" function which does pattern matching :(

Original issue reported on code.google.com by mar...@unitedtickets.ee on 29 Aug 2012 at 8:23

GoogleCodeExporter commented 8 years ago
can you please provide more info, such as sample of table structure and example 
of API usage?

Original comment by i...@polevoy.org on 29 Aug 2012 at 8:32

GoogleCodeExporter commented 8 years ago
this is written quickly in abstract language:

create table user (
   name text.
   surname text,
   middlename text
   dob date,
   haircolor text
)

for (i = 0 to 200 000) {
   insert into user values ('jacob', null, null, null, null);
}

List<usermodel> um = usermodel.findall();

for(usermodel user : um) {
   if (user.get("name") != null)
      some-other-object.setName(user.get("name"));
   if (user.get("surname") != null)
      some-other-object.setSurName(user.get("surname"));
   if (user.get("middlename") != null)
      some-other-object.setMiddleName(user.get("middlename"));
   if (user.get("dob") != null)
      some-other-object.setdob(user.get("dob"));
   if (user.get("haircolor") != null)
      some-other-object.setHair(user.get("haircolor"));
}

The last four if's will result in huge comparisons because the values are 
nulls. Take a look at Model.java line 1022. There you will see that user.get 
will ultimately result in trying to pluralize or some other magic to find the 
answer which results in very very slow performance.

Original comment by mar...@unitedtickets.ee on 29 Aug 2012 at 8:50

GoogleCodeExporter commented 8 years ago
Can this be made optional?

Like setting some static boolean variable, or passing one along with get? Or 
perhaps creating an additional get method which simply only tries to get from 
hash table and returns null if nothing is found like it is done for column "id" 
now.

Original comment by ma...@unitedtickets.ee on 1 Sep 2012 at 11:31

GoogleCodeExporter commented 8 years ago
exactly, I was thinking along the same lines. I will create an optional system 
property that will turn it off. This way, all existing projects that 
potentially depend on this logic will not brake. 

Original comment by i...@polevoy.org on 1 Sep 2012 at 2:06

GoogleCodeExporter commented 8 years ago
this has been fixed and pushed to the snapshot repo, please see:
http://ipsolutionsdev.com/activejdbc/org/javalite/activejdbc/Model.html#get(java
.lang.String)
for a new system property. 
The new snapshot 1.4.4-SNAPSHOT has been pushed to the snapshot repo:
https://oss.sonatype.org/content/repositories/snapshots/org/javalite/
Please, try it out, if works for you, I will make a new release. 

thanks,
igor

Original comment by ipolevoy@gmail.com on 1 Sep 2012 at 9:23

GoogleCodeExporter commented 8 years ago
Yes it works,

thank you Igor

Original comment by mar...@unitedtickets.ee on 2 Sep 2012 at 4:21

GoogleCodeExporter commented 8 years ago
all right, I will make a new release then 

Original comment by i...@polevoy.org on 2 Sep 2012 at 4:54

GoogleCodeExporter commented 8 years ago
new release 1.4.4 is out, will be sync-ed to Maven central in a few hours

Original comment by ipolevoy@gmail.com on 2 Sep 2012 at 5:50