PostgreSQL: sharp drop in performance of SELECT NOT IN (SELECT ..) by strings (filenames)
===

**THE PROBLEM:**

    SELECT new_filename
    FROM tmp2_import_lightnings_filenames
    WHERE new_filename
    	NOT IN (SELECT filename FROM service.import_lightnings_filenames LIMIT 64500)
    LIMIT 1;
Execution time: **62 ms**.

    SELECT new_filename
    FROM tmp2_import_lightnings_filenames
    WHERE new_filename
    	NOT IN (SELECT filename FROM service.import_lightnings_filenames LIMIT 65000)
    LIMIT 1;

Execution time: **4.742 sec ms**.

Enormous lag! And it increases expanentialy.

**TABLES' STRUCTURE:**

    CREATE TABLE public.tmp2_import_lightnings_filenames (
      new_filename VARCHAR(63) NOT NULL, 
      CONSTRAINT tmp2_import_lightnings_filenames_pkey PRIMARY KEY(new_filename)
    ) WITHOUT OIDS;
Table size: 7304 strings

Data example: */xml/2012-07-13/01/01-24.xml*

    CREATE TABLE service.import_lightnings_filenames (
      id SERIAL, 
      filename VARCHAR(63) NOT NULL, 
      imported BOOLEAN DEFAULT false, 
      strokes_num INTEGER, 
      CONSTRAINT import_lightnings_filenames_pkey PRIMARY KEY(id)
    ) WITHOUT OIDS;
    
    COMMENT ON TABLE service.import_lightnings_filenames
    IS 'Служебная таблица для импорта данных о молниевых разрядах.';
    
    CREATE UNIQUE INDEX import_lightnings_filenames_idx ON service.import_lightnings_filenames
      USING btree (filename COLLATE pg_catalog."default");
Table size: 70812 strings

Data example: *44;/xml/2012-05-26/12/12-18.xml;TRUE;NULL*

**QUERY PLAN:**

     Limit  (cost=0.00..2125.03 rows=1 width=29)
       ->  Seq Scan on tmp2_import_lightnings_filenames  (cost=0.00..7760626.00 rows=3652 width=29)
             Filter: (NOT (SubPlan 1))
             SubPlan 1
               ->  Materialize  (cost=0.00..1962.49 rows=65000 width=29)
                     ->  Limit  (cost=0.00..1192.49 rows=65000 width=29)
                           ->  Seq Scan on import_lightnings_filenames  (cost=0.00..1299.12 rows=70812 width=29)
    (7 rows)

What do I do wrong?
