Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #71885

Re: hashing strings to integers for sqlite3 keys

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'say,': 0.05; 'schema': 0.05; 'indexing': 0.07; 'nicely': 0.07; 'postgresql': 0.07; '22,': 0.09; 'function,': 0.09; 'integers': 0.09; 'integral': 0.09; 'key.': 0.09; 'postgresql,': 0.09; 'sake': 0.09; 'structure,': 0.09; 'subject:keys': 0.09; 'things,': 0.09; 'worse': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'anyway': 0.14; 'adam': 0.16; 'check.': 0.16; 'duplicates': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hashes': 0.16; 'messages)': 0.16; 'subject:sqlite3': 0.16; 'suppressing': 0.16; 'uniqueness': 0.16; 'wrote:': 0.18; 'module': 0.19; 'thu,': 0.19; 'seems': 0.21; 'input': 0.22; 'select': 0.22; 'separate': 0.22; 'tests': 0.22; 'cc:addr:python.org': 0.22; 'headers': 0.24; 'integer': 0.24; 'logical': 0.24; 'stick': 0.24; '---': 0.24; 'cc:2**0': 0.24; 'primary': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'testing': 0.29; 'possibility': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'usually': 0.31; 'equality': 0.31; 'quite': 0.32; 'text': 0.33; 'table': 0.34; 'problem': 0.35; "can't": 0.35; 'one,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'library.': 0.36; 'right?': 0.36; 'should': 0.36; 'performance': 0.37; 'files': 0.38; 'pm,': 0.38; 'rather': 0.38; 'moving': 0.39; 'enough': 0.39; 'even': 0.60; 'read': 0.60; 'solve': 0.60; "you're": 0.61; "you'll": 0.62; 'guarantee': 0.63; 'news': 0.67; 'checks.': 0.84; 'collision': 0.84; 'plays': 0.84; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=+mzfwDkteIMrPXglQNvrwNNXgkAaiIxrsDnjVstcVWU=; b=XJpQuSZBi+PUJP7eF6WPeB84aMGBY6At5yMw/a2HImj9ZOgT0o6FmB5GY78++gGi7C knHHnxh3SzA+nMUgLF38VnAKVOnAt+DX3tWGYoMwWOYLtPfSEo7QJp/Pxn3VQaZ+sy9J Bbwx9dDG/XuR9HomHvEahQ8oQDsBmRV5qeSsN8po1nptzitZnOkGGmcpn/ajyZV7ti4T PmXy0FRNVgng768Z3DntFXj6xb7SrZ2t/rUeOQ84HEBUJtkVVTCnMANzwqVvrgfVS0UC GrMlRzc1T4S6ePL53JpnB4RoyzQsiNLpuqvmt9/kFFm1RmC6OjU5edVGzC+uTi0ke2Hi VEuA==
MIME-Version 1.0
X-Received by 10.52.93.201 with SMTP id cw9mr194379vdb.80.1400763814387; Thu, 22 May 2014 06:03:34 -0700 (PDT)
In-Reply-To <jn415bx6uf.ln2@news.ducksburg.com>
References <jn415bx6uf.ln2@news.ducksburg.com>
Date Thu, 22 May 2014 23:03:34 +1000
Subject Re: hashing strings to integers for sqlite3 keys
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.10219.1400763822.18130.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1400763822 news.xs4all.nl 2936 [2001:888:2000:d::a6]:51663
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:71885

Show key headers only | View raw


On Thu, May 22, 2014 at 9:47 PM, Adam Funk <a24061@ducksburg.com> wrote:
> I'm using Python 3.3 and the sqlite3 module in the standard library.
> I'm processing a lot of strings from input files (among other things,
> values of headers in e-mail & news messages) and suppressing
> duplicates using a table of seen strings in the database.
>
> It seems to me --- from past experience with other things, where
> testing integers for equality is faster than testing strings, as well
> as from reading the SQLite3 documentation about INTEGER PRIMARY KEY
> --- that the SELECT tests should be faster if I am looking up an
> INTEGER PRIMARY KEY value rather than TEXT PRIMARY KEY.  Is that
> right?

It might be faster to use an integer primary key, but the possibility
of even a single collision means you can't guarantee uniqueness
without a separate check. I don't know sqlite3 well enough to say, but
based on what I know of PostgreSQL, it's usually best to make your
schema mimic your logical structure, rather than warping it for the
sake of performance. With a good indexing function, the performance of
a textual PK won't be all that much worse than an integral one, and
everything you do will read correctly in the code - no fiddling around
with hashes and collision checks.

Stick with the TEXT PRIMARY KEY and let the database do the database's
job. If you're processing a really large number of strings, you might
want to consider moving from sqlite3 to PostgreSQL anyway (I've used
psycopg2 quite happily), as you'll get better concurrency; and that
might solve your performance problem as well, as Pg plays very nicely
with caches.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

hashing strings to integers for sqlite3 keys Adam Funk <a24061@ducksburg.com> - 2014-05-22 12:47 +0100
  Re: hashing strings to integers for sqlite3 keys Peter Otten <__peter__@web.de> - 2014-05-22 14:58 +0200
    Re: hashing strings to integers for sqlite3 keys Adam Funk <a24061@ducksburg.com> - 2014-05-22 14:41 +0100
      Re: hashing strings to integers for sqlite3 keys Chris Angelico <rosuav@gmail.com> - 2014-05-23 00:08 +1000
        Re: hashing strings to integers for sqlite3 keys Adam Funk <a24061@ducksburg.com> - 2014-05-22 15:40 +0100
  Re: hashing strings to integers for sqlite3 keys Chris Angelico <rosuav@gmail.com> - 2014-05-22 23:03 +1000
    Re: hashing strings to integers for sqlite3 keys Adam Funk <a24061@ducksburg.com> - 2014-05-22 14:47 +0100
  Re: hashing strings to integers for sqlite3 keys Tim Chase <python.list@tim.thechases.com> - 2014-05-22 08:09 -0500
    Re: hashing strings to integers for sqlite3 keys Adam Funk <a24061@ducksburg.com> - 2014-05-22 14:54 +0100
      Re: hashing strings to integers for sqlite3 keys Chris Angelico <rosuav@gmail.com> - 2014-05-23 00:14 +1000
        Re: hashing strings to integers for sqlite3 keys Adam Funk <a24061@ducksburg.com> - 2014-05-22 15:47 +0100
          Re: hashing strings to integers for sqlite3 keys Chris Angelico <rosuav@gmail.com> - 2014-05-23 01:09 +1000
          Re: hashing strings to integers for sqlite3 keys Peter Otten <__peter__@web.de> - 2014-05-22 17:34 +0200
            hashing strings to integers (was: hashing strings to integers for sqlite3 keys) Adam Funk <a24061@ducksburg.com> - 2014-05-23 11:27 +0100
              Re: hashing strings to integers Adam Funk <a24061@ducksburg.com> - 2014-05-23 11:36 +0100
                Re: hashing strings to integers Chris Angelico <rosuav@gmail.com> - 2014-05-23 21:01 +1000
              Re: hashing strings to integers (was: hashing strings to integers for sqlite3 keys) Chris Angelico <rosuav@gmail.com> - 2014-05-23 20:59 +1000
                Re: hashing strings to integers Adam Funk <a24061@ducksburg.com> - 2014-05-27 16:13 +0100
                Re: hashing strings to integers Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-05-27 17:02 +0000
                Re: hashing strings to integers Chris Angelico <rosuav@gmail.com> - 2014-05-28 05:16 +1000
                Re: hashing strings to integers Dan Sommers <dan@tombstonezero.net> - 2014-05-28 01:55 +0000
                Re: hashing strings to integers Adam Funk <a24061@ducksburg.com> - 2014-06-03 11:29 +0100
                Re: hashing strings to integers Adam Funk <a24061@ducksburg.com> - 2014-06-03 11:32 +0100
              Re: hashing strings to integers Terry Reedy <tjreedy@udel.edu> - 2014-05-23 15:10 -0400
                Re: hashing strings to integers Adam Funk <a24061@ducksburg.com> - 2014-05-27 16:20 +0100
  Re: hashing strings to integers for sqlite3 keys alister <alister.nospam.ware@ntlworld.com> - 2014-05-22 14:48 +0000

csiph-web