Skip to content

Commit

Permalink
Merge pull request #3 from orsinium-labs/drop-duplicate-row
Browse files Browse the repository at this point in the history
drop duplicate `pages` row from `total_size`
  • Loading branch information
orsinium authored Feb 3, 2023
2 parents ea96eaa + 20029fb commit 7891843
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 8 deletions.
11 changes: 11 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
%{
configs: [
%{
name: "default",
strict: true,
checks: [
{Credo.Check.Design.TagTODO, false},
]
}
]
}
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ EctoSQLite3Extras.table_size({MyProject.Repo, self()})

## Available queries

1. `total_size`. Total size of all tables and indices. It's a summary talbe, it has only 2 columns: `name` and `value`. Rows:
1. `total_size`. The total size of all tables and indices. It's a summary table, it has only 2 columns: `name` and `value`. Rows:
1. `cells`: The number of cells in the DB. Each value stored in the DB is represented as at least one cell. So, the number of cells correlates with the number of records in the DB.
1. `payload_size`: How much space the actual useful payload takes in the DB.
1. `unused_size`: How much space in the DB is reserved, not used yet, and can be used later to store more data. This is a surplus that occurs because SQLite allocates space for data in chunks ("pages").
1. `vacuum_size`: How much space is unused and cannot be used for the future data. You can run [VACUUM](https://www.sqlite.org/lang_vacuum.html) command to reduce it.
1. `vacuum_size`: How much space is unused and cannot be used for future data. You can run [VACUUM](https://www.sqlite.org/lang_vacuum.html) command to reduce it.
1. `page_size`: The total space occupied by all pages. Each page is a single chunk of space allocated by SQLite. This number is the sum of `payload_size`, `unused_size`, and `vacuum_size`.
1. `pages`: The total number of pages.
1. `pages: leaf`: The pages that store the actual data. Read [SQLite Internals: Pages & B-trees](https://fly.io/blog/sqlite-internals-btree/) to learn more.
1. `pages: internal`: The pages that store ranges for leaf pages for a faster lookup. Sometimes also called "interior pages".
1. `pages: overflow`: The pages that store chunks of big data that doesn't fit in a single leaf page.
1. `pages: overflow`: The pages that store chunks of big data that don't fit in a single leaf page.
1. `pages: table`: The pages used for storing data for tables.
1. `pages: index`: The pages used for storing indices.
1. `table_size`. Information about the space used (and unused) by all tables. Based on the [dbstat](https://www.sqlite.org/dbstat.html) virtual table.
Expand All @@ -65,7 +65,7 @@ EctoSQLite3Extras.table_size({MyProject.Repo, self()})
1. `index_size`. Size of all indices.
1. `name`: The index name.
1. `table_name`: The table where the index is defined.
1. `column_name`: The name of the column being indexed. This columns is NULL if the column is the rowid or an expression.
1. `column_name`: The name of the column being indexed. This column is NULL if the column is the rowid or an expression.
1. `payload_size`.
1. `unused_size`.
1. `page_size`.
Expand All @@ -75,7 +75,7 @@ EctoSQLite3Extras.table_size({MyProject.Repo, self()})
1. `sequence_number`. Sequence numbers of autoincrement columns. Generated based on the [sqlite_sequence](https://renenyffenegger.ch/notes/development/databases/SQLite/internals/schema-objects/sqlite_sequence) table. The query will fail if there are no autoincrement columns in the DB yet.
1. `table_name`.
1. `sequence_number`.
1. `pragma`. List values of PRAGMAs (settings). Only includes the ones that have an integer or a boolean value. For bravity, the ones with `0` (`false`) value are excluded from the output (based on the observation that this is the default value for most of the PRAGMAs). Check out the SQLite documentation to learn more about what each PRAGMA means: [PRAGMA Statements](https://www.sqlite.org/pragma.html).
1. `pragma`. List values of PRAGMAs (settings). Only includes the ones that have an integer or a boolean value. For brevity, the ones with the `0` (`false`) value are excluded from the output (based on the observation that this is the default value for most of the PRAGMAs). Check out the SQLite documentation to learn more about what each PRAGMA means: [PRAGMA Statements](https://www.sqlite.org/pragma.html).
1. `name`: the name of the PRAGMA as listed in the SQLite documentation.
1. `value`: the value of the PRAGMA. The `true` value is converted into `1` (and `false` is simply excluded).
1. `integrity_check`. Run integrity checks on the database. Executes [PRAGMA integrity_check](https://www.sqlite.org/pragma.html#pragma_integrity_check) and returns the resulting messages.
Expand Down
2 changes: 2 additions & 0 deletions lib/ecto_sqlite3_extras.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ defmodule EctoSQLite3Extras do

@doc """
Sequence numbers of autoincrement columns.
The query will fail if there are no autoincrement columns in the DB yet.
"""
@spec sequence_number(repo(), keyword()) :: any()
def sequence_number(repo, opts \\ []), do: query(:sequence_number, repo, opts)
Expand Down
3 changes: 3 additions & 0 deletions lib/queries/sequence_number.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ defmodule EctoSQLite3Extras.SequenceNumber do
}
end

# TODO(@orsinium): The query fails if the table doesn't exist.
# The table is created only when the first autoincrement column is created.
# Can we fix it without doing INSERTs?
def query(_args \\ []) do
"""
/* from ecto_sqlite3_extras */
Expand Down
1 change: 0 additions & 1 deletion lib/queries/total_size.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ defmodule EctoSQLite3Extras.TotalSize do
UNION ALL SELECT 'unused_size', SUM(unused) FROM dbstat
UNION ALL SELECT 'vacuum_size', SUM(pgsize) - SUM(payload) - SUM(unused) FROM dbstat
UNION ALL SELECT 'page_size', SUM(pgsize) FROM dbstat
UNION ALL SELECT 'pages', COUNT(*) FROM dbstat
UNION ALL SELECT 'pages: leaf', COUNT(*)
FROM dbstat WHERE pagetype = 'leaf'
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule EctoSQLite3Extras.MixProject do
use Mix.Project
@github_url "https://github.com/orsinium-labs/ecto_sqlite3_extras"
@version "1.1.5"
@version "1.1.6"

def project do
[
Expand Down
1 change: 0 additions & 1 deletion test/ecto_sqlite3_extras_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ defmodule EctoSQLite3ExtrasTest do
["unused_size", "82.0 KB"],
["vacuum_size", "184.8 KB"],
["page_size", "864.0 KB"],
["pages", 864],
["pages: leaf", 840],
["pages: internal", 24],
["pages: overflow", 0],
Expand Down

0 comments on commit 7891843

Please sign in to comment.