Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/35799-software-titles
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Optimized api/latest/fleet/software/titles endpoint.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package tables

import (
"database/sql"
"fmt"
)

func init() {
MigrationClient.AddMigration(Up_20260226182000, Down_20260226182000)
}

func Up_20260226182000(tx *sql.Tx) error {
// Drop the old index that doesn't include global_stats or DESC on hosts_count
_, err := tx.Exec(`
DROP INDEX idx_software_titles_host_counts_team_counts_title
ON software_titles_host_counts
`)
if err != nil {
return fmt.Errorf("failed to drop old index: %w", err)
}

// Create new covering index that includes global_stats.
// The optimized title query filters by (team_id, global_stats) then joins
// software_titles for the name-based secondary sort, so the index is used
// for filtering, not ordering.
_, err = tx.Exec(`
CREATE INDEX idx_software_titles_host_counts_team_global_hosts
ON software_titles_host_counts (team_id, global_stats, hosts_count, software_title_id)
`)
if err != nil {
return fmt.Errorf("failed to create new index: %w", err)
}

return nil
}

func Down_20260226182000(_ *sql.Tx) error {
return nil
}
6 changes: 3 additions & 3 deletions server/datastore/mysql/schema.sql

Large diffs are not rendered by default.

Loading
Loading