一个小测试:
CREATE TABLE test2 (
id serial PRIMARY KEY,
num integer,
short_text varchar(32),
longer_text varchar(1000),
long_long_text text
);
INSERT INTO test2 (num, short_text, longer_text, long_long_text)
SELECT i, lpad('', 32, 'abcdefeghji'), lpad('', 1000, 'abcdefeghji'), lpad('', (random() * 10000)::integer, 'abcdefeghji')
FROM generate_series(1, 10000) a(i);
ANALYZE test2;
SELECT * FROM test2;
[...]
Time: 1091.331 ms
SELECT num FROM test2;
[...]
Time: 21.310 ms
将查询限制为前250行(WHERE num <= 250
)分别导致34.539 ms和8.343 ms。long_long_text
从此有限的集合中选择所有内容都将花费18.432 ms。从您的角度来看,这表明PG足够聪明。