30
loading...
This website collects cookies to deliver better user experience
python -c "from sqlalchemy import create_engine;import pandas;import io;import urllib.request;
pandas.read_csv(io.StringIO(urllib.request.urlopen('https://github.com/fivethirtyeight/data/blob/master/avengers/avengers.csv?raw=True').read().decode('utf-8', errors='ignore'))).to_sql('avengers',
create_engine('postgresql+psycopg2://franck:[email protected]:5433/yugabyte'), if_exists='replace', method='multi')"
yugabyte=> select count(*) from avengers;
count
-------
173
yugabyte=> select indexdef from pg_indexes
where ( schemaname , tablename )
= ( 'public' , 'avengers' )
;
indexdef
--------------------------------------------------------------------------
CREATE INDEX ix_avengers_index ON public.avengers USING lsm (index HASH)
yugabyte=> explain (analyze, verbose)
select index,"Name/Alias","Appearances","Gender","Year","Death1","Notes"
from avengers;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------
Seq Scan on public.avengers (cost=0.00..100.00 rows=1000 width=152) (actual time=120.770..481.221 rows=173 loops=1)
Output: index, "Name/Alias", "Appearances", "Gender", "Year", "Death1", "Notes"
yugabyte=> select index,"Name/Alias","Appearances","Gender","Year","Death1","Notes"
from avengers where index=73;
index | Name/Alias | Appearances | Gender | Year | Death1 | Notes
------------+-----------------------+-------------+--------+------+--------+-----------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
73 | Peter Benjamin Parker | 4333 | MALE | 1990 | YES | Since joining the New Avengers: First death Killed by Morlun. Ressurected in a brand new body. Died in Amazing Spider-
Man #700. Eventually mainfested in his body that Octavious stole and then took over again.
(1 row)
yugabyte=> explain (analyze, verbose)
select index,"Name/Alias","Appearances","Gender","Year","Death1","Notes"
from avengers where index=73;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------
Index Scan using avengers_pkey on public.avengers (cost=0.00..4.11 rows=1 width=152) (actual time=120.434..120.437 rows=1 loops=1)
Output: index, "Name/Alias", "Appearances", "Gender", "Year", "Death1", "Notes"
Index Cond: (avengers.index = 73)
yugabyte=> explain (analyze, verbose)
select index,"Name/Alias","Appearances","Gender","Year","Death1","Notes"
from avengers where index in (73,6);
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------
Index Scan using avengers_pkey on public.avengers (cost=0.00..4.11 rows=1 width=152) (actual time=841.051..841.057 rows=2 loops=1)
Output: index, "Name/Alias", "Appearances", "Gender", "Year", "Death1", "Notes"
Index Cond: (avengers.index = ANY ('{73,6}'::bigint[]))
yugabyte=> select index,"Name/Alias","Appearances","Gender","Year","Death1","Notes"
from avengers where index<5;
index | Name/Alias | Appearances | Gender | Year | Death1 | Notes
------------+-----------------------------+-------------+--------+------+--------+-----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------
2 | Anthony Edward "Tony" Stark | 3068 | MALE | 1963 | YES | Death: "Later while under the influence of Immortus Stark committed a number of horrible acts and was killed.'
This set up young Tony. Franklin Richards later brought him back
0 | Henry Jonathan "Hank" Pym | 1269 | MALE | 1963 | YES | Merged with Ultron in Rage of Ultron Vol. 1. A funeral was held.
3 | Robert Bruce Banner | 2089 | MALE | 1963 | YES | Dies in Ghosts of the Future arc. However "he had actually used a hidden Pantheon base to survive"
1 | Janet van Dyne | 1165 | FEMALE | 1963 | YES | Dies in Secret Invasion V1:I8. Actually was sent tto Microverse later recovered
4 | Thor Odinson | 2402 | MALE | 1963 | YES | Dies in Fear Itself brought back because that's kind of the whole point. Second death in Time Runs Out has not y
et returned
(5 rows)
yugabyte=> explain (analyze, verbose)
select index,"Name/Alias","Appearances","Gender","Year","Death1","Notes"
from avengers where index<5;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------
Seq Scan on public.avengers (cost=0.00..102.50 rows=1000 width=152) (actual time=120.801..481.287 rows=5 loops=1)
Output: index, "Name/Alias", "Appearances", "Gender", "Year", "Death1", "Notes"
Filter: (avengers.index < 5)
Rows Removed by Filter: 168
yugabyte=> create index i0 on avengers("Appearances");
CREATE INDEX
yugabyte=> select indexdef from pg_indexes
where ( schemaname , tablename ) = ( 'public' , 'avengers' ) ;
indexdef
-------------------------------------------------------------------------------
CREATE INDEX ix_avengers_index ON public.avengers USING lsm (index HASH)
CREATE INDEX i0 ON public.avengers USING lsm ("Appearances" HASH)
yugabyte=> select index,"Name/Alias","Appearances","Gender","Year","Death1","Notes"
from avengers where "Appearances"<5 order by "Appearances";
index | Name/Alias | Appearances | Gender | Year | Death1 | Notes
------------+---------------+-------------+--------+------+--------+-------------------------------------------------------------------------------------
125 | Fiona | 2 | FEMALE | 1900 | NO |
39 | Moira Brandon | 2 | FEMALE | 1993 | YES | Died in her second appearance earns honorary Avengers status doing so. Stays dead.
68 | Doug Taggert | 3 | MALE | 2005 | YES | Accidently killed by Zaran
65 | Gene Lorrene | 4 | MALE | 2005 | NO |
(4 rows)
yugabyte=> explain (analyze, verbose)
select index,"Name/Alias","Appearances","Gender","Year","Death1","Notes"
from avengers where "Appearances"<5 order by "Appearances";
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------
Sort (cost=152.33..154.83 rows=1000 width=152) (actual time=481.279..481.280 rows=4 loops=1)
Output: index, "Name/Alias", "Appearances", "Gender", "Year", "Death1", "Notes"
Sort Key: avengers."Appearances"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on public.avengers (cost=0.00..102.50 rows=1000 width=152) (actual time=120.797..481.268 rows=4 loops=1)
Output: index, "Name/Alias", "Appearances", "Gender", "Year", "Death1", "Notes"
Filter: (avengers."Appearances" < 5)
Rows Removed by Filter: 169
yugabyte=> explain (analyze, verbose)
select index,"Name/Alias","Appearances","Gender","Year","Death1","Notes"
from avengers where "Appearances" in (1,2,3,4,5) order by "Appearances";
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------
Sort (cost=5.43..5.45 rows=10 width=152) (actual time=480.476..480.477 rows=4 loops=1)
Output: index, "Name/Alias", "Appearances", "Gender", "Year", "Death1", "Notes"
Sort Key: avengers."Appearances"
Sort Method: quicksort Memory: 25kB
-> Index Scan using i0 on public.avengers (cost=0.00..5.26 rows=10 width=152) (actual time=359.614..480.466 rows=4 loops=1)
Output: index, "Name/Alias", "Appearances", "Gender", "Year", "Death1", "Notes"
Index Cond: (avengers."Appearances" = ANY ('{1,2,3,4,5}'::bigint[]))
yugabyte=> drop index i0;
DROP INDEX
yugabyte=> create index i0 on avengers("Appearances" asc);
CREATE INDEX
yugabyte=> explain (analyze, verbose)
select index,"Name/Alias","Appearances","Gender","Year","Death1","Notes"
from avengers where "Appearances"<5 order by "Appearances";
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------
Index Scan using i0 on public.avengers (cost=0.00..5.22 rows=10 width=152) (actual time=599.444..599.452 rows=4 loops=1)
Output: index, "Name/Alias", "Appearances", "Gender", "Year", "Death1", "Notes"
Index Cond: (avengers."Appearances" < 5)
yugabyte=> select index,"Name/Alias","Appearances","Gender","Year","Death1","Notes"
from avengers where "Appearances">2000 order by "Appearances";
index | Name/Alias | Appearances | Gender | Year | Death1 | Notes
------------+-----------------------------+-------------+--------+------+--------+-----------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
3 | Robert Bruce Banner | 2089 | MALE | 1963 | YES | Dies in Ghosts of the Future arc. However "he had actually used a hidden Pantheon base to survive"
57 | Reed Richards | 2125 | MALE | 1989 | NO |
40 | Benjamin Jacob Grimm | 2305 | MALE | 1986 | YES | Once killed during a battle with Doctor Doom.' Brought back by the FF when they literally went to Heaven to get
him.
4 | Thor Odinson | 2402 | MALE | 1963 | YES | Dies in Fear Itself brought back because that's kind of the whole point. Second death in Time Runs Out has not y
et returned
2 | Anthony Edward "Tony" Stark | 3068 | MALE | 1963 | YES | Death: "Later while under the influence of Immortus Stark committed a number of horrible acts and was killed.'
This set up young Tony. Franklin Richards later brought him back
92 | James "Logan" Howlett | 3130 | MALE | 2005 | YES | Died in Death_of_Wolverine_Vol_1_4. Has not yet returned
6 | Steven Rogers | 3458 | MALE | 1964 | YES | Dies at the end of Civil War. Later comes back.
73 | Peter Benjamin Parker | 4333 | MALE | 1990 | YES | Since joining the New Avengers: First death Killed by Morlun. Ressurected in a brand new body. Died in Amazing S
pider-Man #700. Eventually mainfested in his body that Octavious stole and then took over again.
(8 rows)
yugabyte=> explain (analyze, verbose)
select index,"Name/Alias","Appearances","Gender","Year","Death1","Notes"
from avengers where "Appearances">2000 order by "Appearances";
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------
Index Scan using i0 on public.avengers (cost=0.00..5.22 rows=10 width=152) (actual time=239.388..239.401 rows=8 loops=1)
Output: index, "Name/Alias", "Appearances", "Gender", "Year", "Death1", "Notes"
Index Cond: (avengers."Appearances" > 2000)
yugabyte=> create index i1 on avengers("Name/Alias");
CREATE INDEX
yugabyte=> select index,"Name/Alias","Appearances","Gender","Year","Death1","Notes"
from avengers where "Name/Alias"='Peter Benjamin Parker';
index | Name/Alias | Appearances | Gender | Year | Death1 | Notes
------------+-----------------------+-------------+--------+------+--------+-----------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
73 | Peter Benjamin Parker | 4333 | MALE | 1990 | YES | Since joining the New Avengers: First death Killed by Morlun. Ressurected in a brand new body. Died in Amazing Spider-
Man #700. Eventually mainfested in his body that Octavious stole and then took over again.
(1 row)
yugabyte=> explain (analyze, verbose)
select index,"Name/Alias","Appearances","Gender","Year","Death1","Notes"
from avengers where "Name/Alias"='Peter Benjamin Parker';
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------
Index Scan using i1 on public.avengers (cost=0.00..5.22 rows=10 width=152) (actual time=239.840..239.844 rows=1 loops=1)
Output: index, "Name/Alias", "Appearances", "Gender", "Year", "Death1", "Notes"
Index Cond: (avengers."Name/Alias" = 'Peter Benjamin Parker'::text)
yugabyte=> explain (analyze, verbose)
select index,"Name/Alias","Appearances","Gender","Year","Death1","Notes"
from avengers where "Name/Alias" like 'Peter% Parker';
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------
Seq Scan on public.avengers (cost=0.00..102.50 rows=1000 width=152) (actual time=479.191..480.680 rows=1 loops=1)
Output: index, "Name/Alias", "Appearances", "Gender", "Year", "Death1", "Notes"
Filter: (avengers."Name/Alias" ~~ 'Peter% Parker'::text)
Rows Removed by Filter: 172
LIKE 'Peter% Parker'
pattern we had to scan all the rows. Can we do better? Let's create a RANGE index:yugabyte=> create index i2 on avengers("Name/Alias" asc);
CREATE INDEX
yugabyte=> explain (analyze, verbose)
select index,"Name/Alias","Appearances","Gender","Year","Death1","Notes"
from avengers where "Name/Alias" like 'Peter% Parker';
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------
Index Scan using i2 on public.avengers (cost=0.00..5.25 rows=10 width=152) (actual time=480.660..480.665 rows=1 loops=1)
Output: index, "Name/Alias", "Appearances", "Gender", "Year", "Death1", "Notes"
Index Cond: ((avengers."Name/Alias" >= 'Peter'::text) AND (avengers."Name/Alias" < 'Petes'::text))
Filter: (avengers."Name/Alias" ~~ 'Peter% Parker'::text)
yugabyte=> drop index i1;
DROP INDEX