简体   繁体   中英

SQL query Union All

I am combining around 7 different tables(requirement) from OracleDB by forming an sql query with Union all condition. Currently I have included it as a native query in JPA. I see it is taking too much time. Records size increases day by day. But I see more time taken while executing from java side. So please let me know is there a way I can optimize the SQL query performance.

  Select distinct e.name, e.project, e.marks, e.address from table1 where e.date > sysdate
union all

 Select distinct m.name, m.project, m.marks, m.address from table2 where m.date > sysdate

etc for other tables

When fetching records using JPA, it generates additional classes around your entities necessary to manage its state(hence 'persistency management'). If the resultset is only used for reading content, you can define DTO classes and mark them as Readonly (how to do this depends on the JPA framework you use). This reduces the overhead of JPA and will increase performance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM