Schrift
[thread]11618[/thread]

Mail-Benachrichtigung oder RSS ... (Seite 3)



<< |< 1 2 3 >| >> 23 Einträge, 3 Seiten
lux
 2008-04-29 16:45
#109001 #109001
User since
2007-09-15
104 Artikel
BenutzerIn
[Homepage]
user image
Hagen+2008-04-29 12:43:49--
Habe das ganze jetzt noch mal mehrmals mit Joins ausprobiert. Aber entweder ich habe den falschen Ansatz gewählt ... oder es gibt keinen Unterschied. Jedenfalls sind die Ergebnisse von 'Explain' immer die gleichen ... oder ich habe die sinnvolle Anwendung von joins nicht anwenden können.


Es kann auch sein, dass Dir MySQL einen Strich durch die Rechnung macht. Meines Wissens nach, benutzt MySQL maximal einen Index. Nicht nur bei Joins kann es durchaus Sinn machen, mehrere zu benutzen.

Gruss

Dirk
Blog - Podcast - Frau - Hunde
Schweizer Tastaturen kennen kein sz.
pq
 2008-04-29 17:07
#109002 #109002
User since
2003-08-04
12209 Artikel
Admin1
[Homepage]
user image
mysql benutzt maximal einen index pro tabelle. d.h. auch bei einem join wird nur einer benutzt,
da ja für den join schon eine bedingung ausgewertet werden muss, ob nun indiziert oder nicht.
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem
Hagen
 2008-06-04 12:22
#110713 #110713
User since
2007-09-06
233 Artikel
BenutzerIn
[default_avatar]
Nach etwas längerer Pause doch mal wieder etwas Zeit und Lust hierfür gefunden. Eigentlich stand nur noch die SQL-Anweisung aus (INNER JOIN):
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
sub erzeuge_rss_feed {
### ggf. Beschreibung anpassen ###
        if ($board_id || $thread_id) {
                my $sql; 
                if ($thread_id) { $sql = "SELECT title FROM $PBoard::Config::DbTables{threads} WHERE id = '$thread_id' LIMIT 1"; } # if
                if ($board_id)  { $sql = "SELECT name FROM $PBoard::Config::DbTables{boards} WHERE id = '$board_id' LIMIT 1"; } # if

                my $storage = PBoard::Storage->new( { dbh => undef } );
                my $poard = PBoard->new( { cgi => $cgi, storage => $storage } );
                my $dbh = PBoard::DB::ConnectToDB( $poard );
                $storage->set_dbh( $dbh );
                my $sth = &PBoard::DB::FireSql( $poard, $sql );
                (my $titel) = $sth->fetchrow_array();
                $rss_board_titel .= ' :: '.$titel;
                } # if

### SQL ###
        my $sql = "SELECT boards.id as board_id, threads.id as thread_id, messages.position as position, boards.name as board_name, threads.title as thread_title, messages.message_raw as message_raw";
        $sql .=   "\n" if $debug;
        $sql .=   " FROM $PBoard::Config::DbTables{boards} AS boards";
        $sql .=   " INNER JOIN $PBoard::Config::DbTables{threads} AS threads ON (boards.id = threads.boardID)";
        $sql .=   " INNER JOIN $PBoard::Config::DbTables{messages} AS messages ON (threads.id = messages.thread)";
        $sql .=   "\n" if $debug;
        $sql .=   " WHERE messages.status != 'deleted' AND threads.status != 'onhold' AND threads.status != 'deleted'";
        $sql .=   " AND boards.groupRequired <= 2"; # nur öffentliche Boards
        $sql .=   " AND boards.id = ?" if $board_id;
        $sql .=   " AND threads.id = ?" if $thread_id;
        $sql .=   " AND messages.authorId = ?" if $user_id;
        $sql .=   " AND ((UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(messages.posttime)) <= (? * 24 * 60 * 60))" if lc($action) eq lc('lastMessagesDays');
        $sql .=   " AND messages.position = '1'" if lc($filter) eq lc('no_replies');
        $sql .=   "\n" if $debug;
        $sql .=   " ORDER BY messages.posttime DESC";
        $sql .=   "\n" if $debug;
        $sql .=   " LIMIT ?";

        my @placeholders;
        push @placeholders, $board_id       if $board_id;
        push @placeholders, $thread_id      if $thread_id;
        push @placeholders, $user_id        if $user_id;
        push @placeholders, $last_entries   if lc($action) eq lc('lastMessagesDays');
        if (lc($action) eq lc('lastMessagesDays'))        { push @placeholders, $max_entries; } # if
        elsif (lc($action) eq lc('lastMessagesNumbers'))  { push @placeholders, $last_entries; } # if
        else                                              { push @placeholders, $max_entries; } # ifelse

        if ($debug) {
                print "\n\n$sql\n\n";
                foreach my $item (@placeholders) { print "- Wert(Platzhalter) ->".$item."\n";   } # foreach
                } # if

### DB ###
        my $storage = PBoard::Storage->new( { dbh => undef } );
        my $poard = PBoard->new( { cgi => $cgi, storage => $storage } );
        my $dbh = PBoard::DB::ConnectToDB( $poard );
        $storage->set_dbh( $dbh );
        my $sth = &PBoard::DB::FireSql( $poard, $sql, @placeholders );

### Feed erzeugen ###
        my $rss = new XML::RSS (version => '2.0');
        $rss->channel(title          => $rss_board_titel,
                      link           => $rss_board_link,
                      language       => $rss_language,
                      description    => $rss_description,
                      copyright      => $rss_copyright,
                      docs           => $rss_docs,
                      managingEditor => $rss_managingEditor,
                      webMaster      => $rss_webMaster,
                      );

        my %hash_ref;
        while(my $hash_ref = $sth->fetchrow_hashref) {
                my $link = $rss_board_link.'/thread/'.${$hash_ref}{'thread_id'}.'/startWithMessage='.(int(${$hash_ref}{'position'}/10)*10).'/#MSG'.${$hash_ref}{'position'};
                $rss->add_item(
                        title => ${$hash_ref}{'thread_title'},
                        link  => $link,
                        description => ${$hash_ref}{'message_raw'},
                        );
                } # while
        $sth->finish;

        return $rss->as_string;
        } # sub erzeuge_rss_feed
Gruß
Hagen
<< |< 1 2 3 >| >> 23 Einträge, 3 Seiten



View all threads created 2008-04-10 10:33.