-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[oracle] Missing total.bytes field in tablespace datastream #39787
Changes from 9 commits
5ec5122
4395915
6b89212
2e7a998
683b39d
2ce18ac
0873951
296ed24
f99a0a0
c90771f
f0d0229
4b5160d
d092845
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,31 +11,24 @@ import ( | |
) | ||
|
||
type tempFreeSpace struct { | ||
TablespaceName string | ||
TablespaceSize sql.NullInt64 | ||
UsedSpaceBytes sql.NullInt64 | ||
FreeSpace sql.NullInt64 | ||
} | ||
|
||
func (d *tempFreeSpace) hash() string { | ||
return d.TablespaceName | ||
} | ||
|
||
func (d *tempFreeSpace) eventKey() string { | ||
return d.TablespaceName | ||
TablespaceName string | ||
TotalSpaceBytes sql.NullInt64 | ||
UsedSpaceBytes sql.NullInt64 | ||
FreeSpace sql.NullInt64 | ||
} | ||
|
||
func (e *tablespaceExtractor) tempFreeSpaceData(ctx context.Context) ([]tempFreeSpace, error) { | ||
rows, err := e.db.QueryContext(ctx, "SELECT TABLESPACE_NAME, TABLESPACE_SIZE, ALLOCATED_SPACE, FREE_SPACE FROM DBA_TEMP_FREE_SPACE") | ||
rows, err := e.db.QueryContext(ctx, `WITH sums AS ( SELECT (SELECT SUM(BYTES) FROM DBA_DATA_FILES) + (SELECT SUM(BYTES) FROM DBA_TEMP_FILES) AS TOTAL_SUM FROM dual ) SELECT t.TABLESPACE_NAME, s.TOTAL_SUM, t.ALLOCATED_SPACE, t.FREE_SPACE FROM DBA_TEMP_FREE_SPACE t, sums s `) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you consider something simple as below
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Talking about Niraj's query: See this. (You are using cross join with CTE and DBA_TEMP_FREE_SPACE). Now that I read more and more on this I keep on finding something new. In the query below, the scalar subquery is used to get the TOTAL_SUM from sums CTE compared to your query where CTE is cross-joined with DBA_TEMP_FREE_SPACE. From what I read in most places, scalar subquery seems to be generally a better choice in terms of perf and readability. For example, As the same scalar subquery is running for each row, Oracle might as well cache it and keep using it. In the case of cross joins, it takes up a lot of memory to create a temp table to do the join (unless the DB optimizes it). Find more here: See: https://stackoverflow.com/a/55192080/5821408 and https://asktom.oracle.com/Misc/oramag/on-caching-and-evangelizing-sql.html Try this query?
This query will calculate the total sum separately and display it as a single value for each row. No cross joins. |
||
if err != nil { | ||
return nil, fmt.Errorf("error executing query: %w", err) | ||
} | ||
defer rows.Close() | ||
|
||
results := make([]tempFreeSpace, 0) | ||
|
||
for rows.Next() { | ||
dest := tempFreeSpace{} | ||
if err = rows.Scan(&dest.TablespaceName, &dest.TablespaceSize, &dest.UsedSpaceBytes, &dest.FreeSpace); err != nil { | ||
if err = rows.Scan(&dest.TablespaceName, &dest.TotalSpaceBytes, &dest.UsedSpaceBytes, &dest.FreeSpace); err != nil { | ||
return nil, err | ||
} | ||
results = append(results, dest) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.