window.location.href=window.location.href
virtex_old2=# create table test (id serial, amount numeric, customer numeric);
CREATE TABLE
virtex_old2=# INSERT INTO test(amount,customer) SELECT amount, customer FROM (SELECT generate_series(1,5000000) as id, (random()*10000)::int AS amount, (random()*10000)::int AS customer) as aa;
INSERT 0 5000000
virtex_old2=# SELECT nspname || '.' || relname AS "relation",
virtex_old2-# pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
virtex_old2-# FROM pg_class C
virtex_old2-# LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
virtex_old2-# WHERE nspname NOT IN ('pg_catalog', 'information_schema')
virtex_old2-# AND C.relkind <> 'i'
virtex_old2-# AND nspname !~ '^pg_toast'
virtex_old2-# AND relname = 'test';
relation | total_size
-------------+------------
public.test | 211 MB
(1 row)
virtex_old2=# ALTER TABLE test
ADD COLUMN comment text NOT NULL DEFAULT 'text is here';
ALTER TABLE
virtex_old2=#
virtex_old2=# SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind <> 'i'
AND nspname !~ '^pg_toast'
AND relname = 'test';
relation | total_size
-------------+------------
public.test | 287 MB
virtex_old2=# CREATE INDEX ON test (customer);
CREATE INDEX
virtex_old2=# SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind <> 'i'
AND nspname !~ '^pg_toast'
AND relname = 'test';
relation | total_size
-------------+------------
public.test | 394 MB
(1 row)
virtex_old2=# CREATE INDEX ON test (comment);
CREATE INDEX
virtex_old2=# SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind <> 'i'
AND nspname !~ '^pg_toast'
AND relname = 'test';
relation | total_size
-------------+------------
public.test | 545 MB
(1 row)
ActiveRecord::Base.transaction do
subscriber = Subscriber.create
address = Address.create(subscriber: subscriber)
Number.create(subscriber: subscriber, address: address)
end
Но как можно гармонично это реализовать все это согласованно с моделью?
Да в интернете есть, но они как бы старые и не очень хорошие.
subscriber = Subscriber.new
subscription = sub.subscriptions.build
subscription.periods.build
subscriber.save
def create
subs = Subscriber.new(...)
subs.address.new()
subs.save
end
def create
subs = Subscriber.new(...)
subs.build_address
subs.save
end