I'm a java developer working with jpa, before to define the indexes in my entities i would like to known which one is faster o better to use?.
1 Answer
bigserial
is just shorthand for creating a sequence. So if you include the time it takes to type, bigserial has better "performance" :)
CREATE TABLE tablename (
colname BIGSERIAL
);
Equals
CREATE SEQUENCE tablename_colname_seq;
CREATE TABLE tablename (
colname biginteger DEFAULT nextval('tablename_colname_seq') NOT NULL
);
Also, if you these are your primary keys, then they are already indexed, so you don't need to index them (foreign key columns aren't indexed automatically though, FYI).
For JPA, you should use @GeneratedValue(strategy=GenerationType.IDENTITY)
for PostgreSQL serial/bigserial columns.
-
Tank you. I haven't realized the sequence that is created when the serial or bigserial is used. I'll use the
@GeneratedValue(strategy=GenerationType.IDENTITY)
so my persistence layer can work either mysql or postgresql– OJVMCommented Apr 10, 2014 at 21:33