![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello group, I've a performance question about Postgres. Say I have two queries which are complex and require lots of time (many joins, etc). For my example, I'll just use the simple: SELECT a FROM b [many joins etcetc]; Now when I want to know how many rows were returned, I'll issue: SELECT COUNT(*) FROM b [many joins etcetc]; The question now is: Are those two SELECTs performed twice or is Postgres smart enough to just return the cached number of rows returned? If it isn't, is there a way I can make it understand what I want so the query is only executed once? How about when I embedd the two queries in one transaction, there obviously has to be some kind of caching, as for example: BEGIN TRANSACTION; SELECT now(); SELECT now(); COMMIT; Returns twice the same value for "now()", no matter how much time has passed. Thanks in advance for any enlightenment, Kind Regards, Johannes |
#3
| |||
| |||
|
|
Hello group, I've a performance question about Postgres. Say I have two queries which are complex and require lots of time (many joins, etc). For my example, I'll just use the simple: SELECT a FROM b [many joins etcetc]; Now when I want to know how many rows were returned, I'll issue: SELECT COUNT(*) FROM b [many joins etcetc]; The question now is: Are those two SELECTs performed twice or is Postgres smart enough to just return the cached number of rows returned? If it isn't, is there a way I can make it understand what I want so the query is only executed once? How about when I embedd the two queries in one transaction, there obviously has to be some kind of caching, as for example: BEGIN TRANSACTION; SELECT now(); SELECT now(); COMMIT; Returns twice the same value for "now()", no matter how much time has passed. Thanks in advance for any enlightenment, Kind Regards, Johannes |
#4
| |||
| |||
|
|
Hello group, I've a performance question about Postgres. Say I have two queries which are complex and require lots of time (many joins, etc). For my example, I'll just use the simple: SELECT a FROM b [many joins etcetc]; Now when I want to know how many rows were returned, I'll issue: SELECT COUNT(*) FROM b [many joins etcetc]; The question now is: Are those two SELECTs performed twice or is Postgres smart enough to just return the cached number of rows returned? If it isn't, is there a way I can make it understand what I want so the query is only executed once? How about when I embedd the two queries in one transaction, there obviously has to be some kind of caching, as for example: BEGIN TRANSACTION; SELECT now(); SELECT now(); COMMIT; Returns twice the same value for "now()", no matter how much time has passed. Thanks in advance for any enlightenment, Kind Regards, Johannes |
#5
| |||
| |||
|
|
Hello group, I've a performance question about Postgres. Say I have two queries which are complex and require lots of time (many joins, etc). For my example, I'll just use the simple: SELECT a FROM b [many joins etcetc]; Now when I want to know how many rows were returned, I'll issue: SELECT COUNT(*) FROM b [many joins etcetc]; The question now is: Are those two SELECTs performed twice or is Postgres smart enough to just return the cached number of rows returned? If it isn't, is there a way I can make it understand what I want so the query is only executed once? How about when I embedd the two queries in one transaction, there obviously has to be some kind of caching, as for example: BEGIN TRANSACTION; SELECT now(); SELECT now(); COMMIT; Returns twice the same value for "now()", no matter how much time has passed. Thanks in advance for any enlightenment, Kind Regards, Johannes |
#6
| |||
| |||
|
|
Hello group, I've a performance question about Postgres. Say I have two queries which are complex and require lots of time (many joins, etc). For my example, I'll just use the simple: SELECT a FROM b [many joins etcetc]; Now when I want to know how many rows were returned, I'll issue: SELECT COUNT(*) FROM b [many joins etcetc]; The question now is: Are those two SELECTs performed twice or is Postgres smart enough to just return the cached number of rows returned? If it isn't, is there a way I can make it understand what I want so the query is only executed once? How about when I embedd the two queries in one transaction, there obviously has to be some kind of caching, as for example: BEGIN TRANSACTION; SELECT now(); SELECT now(); COMMIT; Returns twice the same value for "now()", no matter how much time has passed. Thanks in advance for any enlightenment, Kind Regards, Johannes |
#7
| |||
| |||
|
|
Hello group, I've a performance question about Postgres. Say I have two queries which are complex and require lots of time (many joins, etc). For my example, I'll just use the simple: SELECT a FROM b [many joins etcetc]; Now when I want to know how many rows were returned, I'll issue: SELECT COUNT(*) FROM b [many joins etcetc]; The question now is: Are those two SELECTs performed twice or is Postgres smart enough to just return the cached number of rows returned? If it isn't, is there a way I can make it understand what I want so the query is only executed once? How about when I embedd the two queries in one transaction, there obviously has to be some kind of caching, as for example: BEGIN TRANSACTION; SELECT now(); SELECT now(); COMMIT; Returns twice the same value for "now()", no matter how much time has passed. Thanks in advance for any enlightenment, Kind Regards, Johannes |
#8
| |||
| |||
|
|
Hello group, I've a performance question about Postgres. Say I have two queries which are complex and require lots of time (many joins, etc). For my example, I'll just use the simple: SELECT a FROM b [many joins etcetc]; Now when I want to know how many rows were returned, I'll issue: SELECT COUNT(*) FROM b [many joins etcetc]; The question now is: Are those two SELECTs performed twice or is Postgres smart enough to just return the cached number of rows returned? If it isn't, is there a way I can make it understand what I want so the query is only executed once? How about when I embedd the two queries in one transaction, there obviously has to be some kind of caching, as for example: BEGIN TRANSACTION; SELECT now(); SELECT now(); COMMIT; Returns twice the same value for "now()", no matter how much time has passed. Thanks in advance for any enlightenment, Kind Regards, Johannes |
#9
| |||
| |||
|
|
Hello group, I've a performance question about Postgres. Say I have two queries which are complex and require lots of time (many joins, etc). For my example, I'll just use the simple: SELECT a FROM b [many joins etcetc]; Now when I want to know how many rows were returned, I'll issue: SELECT COUNT(*) FROM b [many joins etcetc]; The question now is: Are those two SELECTs performed twice or is Postgres smart enough to just return the cached number of rows returned? If it isn't, is there a way I can make it understand what I want so the query is only executed once? How about when I embedd the two queries in one transaction, there obviously has to be some kind of caching, as for example: BEGIN TRANSACTION; SELECT now(); SELECT now(); COMMIT; Returns twice the same value for "now()", no matter how much time has passed. Thanks in advance for any enlightenment, Kind Regards, Johannes |
#10
| |||
| |||
|
|
now() is docmented as the transaction start time, so theres no caching and inside the same transaction its result should always be the same value. For resolving performance questions EXPLAIN gives You valuable insight. |
![]() |
| Thread Tools | |
| Display Modes | |
| |